<div dir="ltr"><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>
        {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>    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>
</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>
</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></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>
</div><div><br></div><div>Thanks,<br>Dan.<br></div></div></div></div></div>