<tt>
<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Instead of <<"this body ignored">> can you return the atom halt?</div><div><br></div><div>#dontevenhaveanyofmycodewithme:(</div><div><br></div><div>Ivan<br><br>--<br>festina lente<div><br></div></div><div><br>On 30 Oct 2013, at 15:58, Daniel Goertzen <<a href="mailto:[email protected]">[email protected]</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">Well, this sort of works. I tried this in the response handler:<br><div><br> {ok, Req2} = cowboy_req:reply(404, [] , <<"this is the body that gets used">>, Req1),<br> {<<"this body gets ignored">>, Req2, State};<br><br>
<br><br><br></div><div>The client receives a 404 response, but cowboy crashes:<br><br>=ERROR REPORT==== 8-Sep-2013::22:22:03 ===<br>Error in process <0.131.0> with exit value: {function_clause,[{cowboy_req,reply,[200,[],<<31 bytes>>,{http_req,#Port<0.1208>,ranch_tcp,keepalive,<0.131.0>,<<3 bytes>>,'HTTP/1.1',{{192,168,1,187},51017},<<12 bytes>>,undefined,80,<<24 bytes>>,undefined,<<0 bytes>>,undefined,[{channel_num,3}],[{<<10 bytes>>,<<11 bytes>>},{<<4 bytes>>,<<12 bytes>>},{<<6 bytes>>,<<3 bytes>>}],[{<<17 bytes>>,undefined},{<<13 bytes>>,undefined},{<<19 bytes>>,undefined},{<<8 bytes>>,undefined},{<<6 bytes>>,[... <br><br>
<br><br><br></div><div>The issue is that the REST wrapper wants to do the cowboy_req:reply(), and when we do the call we cause the wrapper's call to fail. </div><br><div>Dan.<br></div><div><br></div></div><div class="gmail_extra"><br>
<br><br><div class="gmail_quote">On Tue, Oct 29, 2013 at 4:01 PM, Ivan uemlianin <span dir="ltr"><<a href="mailto:[email protected]" target="_blank">[email protected]</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<div dir="auto"><div>Sorry for terse but I only have a phone. Why can't you return a 404 here? Using something like cowboy:reply(404, ...</div><div><br></div><div>Ivan<br><br>--<br>festina lente<div><br></div></div><div><br>
<div class="h5"><div><br>On 29 Oct 2013, at 21:25, Daniel Goertzen <<a href="mailto:[email protected]" target="_blank">[email protected]</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr"><br>
<div><div><div>My situation is that I have a rest handler that may fail due to invalid url segments. Example situation:<br><br><br><span style="font-family:courier new,monospace">init(_Transport, _Req, _Opts) -><br><br>
{upgrade, protocol, cowboy_rest}.<br><br>content_types_provided(Req, State) -><br> {[{<<"application/json">>, get_json}], Req, State}.<br><br>get_json(Req0, State) -><br> {Params, Req1} = lists:mapfoldl(fun cowboy_req:binding/2, Req0, [param1, param2, param3, ....]),<br><br>
<br>
<br> case catch other_module:request(Params) of<br> {'EXIT', {badarg, _}} -><br></span></div><div><span style="font-family:courier new,monospace"> hmmm, Params were bad and I would like to return a 404 code now.<br><br>
<br>
</span></div><div><span style="font-family:courier new,monospace"> Result -><br> {jiffy:encode(Result), Req1, State}<br> end.<br></span><br><br><br></div><div>So I would like to return a 404 code when my underlying request function fails, but it appears my choices are:<br><br>
<br>
</div><div><br>- return a 200 (ok) response with data.<br></div><div>- crash and cause a 500 (Internal Server Error) response to be returned. Not exactly the sentiment I want.<br></div><div><div><br><br></div><div>Is there some other way to cause a 404 response?<br><br>
<br>
<br></div><div>I realize I could add path constraint functions, but I will be replicating logic from my underlying request function. Furthermore, the constraint functions consider parameters in isolation, so that won't work if the validity of parameters is coupled.<br><br>
<br>
</div><div><br></div><div>Thanks,<br>Dan.<br></div></div></div></div></div><br>
</div></blockquote></div></div><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Extend mailing list</span><br><span><a href="mailto:[email protected]" target="_blank">[email protected]</a></span><br><br>
<span><a href="http://lists.ninenines.eu:81/listinfo/extend" target="_blank">http://lists.ninenines.eu:81/listinfo/extend</a></span><br></div></blockquote></div></blockquote></div><br></div><br>
</div></blockquote></body></html>
</tt>