[99s-extend] REST handler failure
Ivan uemlianin
ivan at llaisdy.com
Tue Oct 29 22:01:30 CET 2013
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/20131029/3df30c1d/attachment.html>
More information about the Extend
mailing list