From c807880f7ac73f813b2660ea81a00f7712a4e793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 29 Aug 2016 12:39:49 +0200 Subject: Add old mailing list archives --- .../archives/extend/2013-October/000287.html | 103 +++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 _build/static/archives/extend/2013-October/000287.html (limited to '_build/static/archives/extend/2013-October/000287.html') diff --git a/_build/static/archives/extend/2013-October/000287.html b/_build/static/archives/extend/2013-October/000287.html new file mode 100644 index 00000000..a4a09c33 --- /dev/null +++ b/_build/static/archives/extend/2013-October/000287.html @@ -0,0 +1,103 @@ + + + + [99s-extend] REST handler failure + + + + + + + + + + +

[99s-extend] REST handler failure

+ Daniel Goertzen + daniel.goertzen at gmail.com +
+ Tue Oct 29 21:25:54 CET 2013 +

+
+ +
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.
+-------------- next part --------------
+An HTML attachment was scrubbed...
+URL: <http://lists.ninenines.eu/archives/extend/attachments/20131029/a9204600/attachment.html>
+
+ + +
+

+ +
+More information about the Extend +mailing list
+ -- cgit v1.2.3