[99s-extend] REST handler failure
Ivan uemlianin
ivan at llaisdy.com
Wed Oct 30 16:27:15 CET 2013
Instead of <<"this body ignored">> can you return the atom halt?
#dontevenhaveanyofmycodewithme:(
Ivan
--
festina lente
On 30 Oct 2013, at 15:58, Daniel Goertzen <daniel.goertzen at gmail.com> wrote:
> Well, this sort of works. I tried this in the response handler:
>
> {ok, Req2} = cowboy_req:reply(404, [] , <<"this is the body that gets used">>, Req1),
> {<<"this body gets ignored">>, Req2, State};
>
>
>
> The client receives a 404 response, but cowboy crashes:
>
> =ERROR REPORT==== 8-Sep-2013::22:22:03 ===
> 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>>,[...
>
>
>
> 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.
>
> Dan.
>
>
>
> On Tue, Oct 29, 2013 at 4:01 PM, Ivan uemlianin <ivan at llaisdy.com> wrote:
>> Sorry for terse but I only have a phone. Why can't you return a 404 here? Using something like cowboy:reply(404, ...
>>
>> Ivan
>>
>> --
>> festina lente
>>
>>
>> On 29 Oct 2013, at 21:25, Daniel Goertzen <daniel.goertzen at gmail.com> wrote:
>>
>>> My situation is that I have a rest handler that may fail due to invalid url segments. Example situation:
>>>
>>>
>>> init(_Transport, _Req, _Opts) ->
>>> {upgrade, protocol, cowboy_rest}.
>>>
>>> content_types_provided(Req, State) ->
>>> {[{<<"application/json">>, get_json}], Req, State}.
>>>
>>> get_json(Req0, State) ->
>>> {Params, Req1} = lists:mapfoldl(fun cowboy_req:binding/2, Req0, [param1, param2, param3, ....]),
>>>
>>> case catch other_module:request(Params) of
>>> {'EXIT', {badarg, _}} ->
>>> hmmm, Params were bad and I would like to return a 404 code now.
>>> Result ->
>>> {jiffy:encode(Result), Req1, State}
>>> end.
>>>
>>>
>>>
>>> So I would like to return a 404 code when my underlying request function fails, but it appears my choices are:
>>>
>>> - return a 200 (ok) response with data.
>>> - crash and cause a 500 (Internal Server Error) response to be returned. Not exactly the sentiment I want.
>>>
>>>
>>> Is there some other way to cause a 404 response?
>>>
>>> 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.
>>>
>>> Thanks,
>>> Dan.
>>> _______________________________________________
>>> Extend mailing list
>>> Extend at lists.ninenines.eu
>>> http://lists.ninenines.eu:81/listinfo/extend
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ninenines.eu/archives/extend/attachments/20131030/6e8ec2f0/attachment.html>
More information about the Extend
mailing list