diff options
Diffstat (limited to 'archives/extend/2013-October/000293.html')
-rw-r--r-- | archives/extend/2013-October/000293.html | 175 |
1 files changed, 175 insertions, 0 deletions
diff --git a/archives/extend/2013-October/000293.html b/archives/extend/2013-October/000293.html new file mode 100644 index 00000000..548908dd --- /dev/null +++ b/archives/extend/2013-October/000293.html @@ -0,0 +1,175 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<HTML> + <HEAD> + <TITLE> [99s-extend] REST handler failure + </TITLE> + <LINK REL="Index" HREF="index.html" > + <LINK REL="made" HREF="mailto:extend%40lists.ninenines.eu?Subject=Re%3A%20%5B99s-extend%5D%20REST%20handler%20failure&In-Reply-To=%3CCAJCf5RzwO4nNcv%3D2Ezf7aMQqFShPhLs4zaYoBBunmzuC7Wp4uQ%40mail.gmail.com%3E"> + <META NAME="robots" CONTENT="index,nofollow"> + <style type="text/css"> + pre { + white-space: pre-wrap; /* css-2.1, curent FF, Opera, Safari */ + } + </style> + <META http-equiv="Content-Type" content="text/html; charset=us-ascii"> + <LINK REL="Previous" HREF="000290.html"> + <LINK REL="Next" HREF="000291.html"> + </HEAD> + <BODY BGCOLOR="#ffffff"> + <H1>[99s-extend] REST handler failure</H1> + <B>Daniel Goertzen</B> + <A HREF="mailto:extend%40lists.ninenines.eu?Subject=Re%3A%20%5B99s-extend%5D%20REST%20handler%20failure&In-Reply-To=%3CCAJCf5RzwO4nNcv%3D2Ezf7aMQqFShPhLs4zaYoBBunmzuC7Wp4uQ%40mail.gmail.com%3E" + TITLE="[99s-extend] REST handler failure">daniel.goertzen at gmail.com + </A><BR> + <I>Wed Oct 30 16:46:37 CET 2013</I> + <P><UL> + <LI>Previous message: <A HREF="000290.html">[99s-extend] REST handler failure +</A></li> + <LI>Next message: <A HREF="000291.html">[99s-extend] REST handler failure +</A></li> + <LI> <B>Messages sorted by:</B> + <a href="date.html#293">[ date ]</a> + <a href="thread.html#293">[ thread ]</a> + <a href="subject.html#293">[ subject ]</a> + <a href="author.html#293">[ author ]</a> + </LI> + </UL> + <HR> +<!--beginarticle--> +<PRE>That's what I was looking for, thanks! + +Dan. + + +On Wed, Oct 30, 2013 at 10:25 AM, Tilman Holschuh <<A HREF="https://lists.ninenines.eu/listinfo/extend">tilman.holschuh at gmail.com</A> +><i> wrote: +</I> +><i> Why not let resource_exists/2 return false when your resource does not +</I>><i> exist? You will get 404 on false. This way you separate the implementation +</I>><i> for turning your data to json from checking if the request went to the +</I>><i> correct resource. +</I>><i> +</I>><i> - Tilman +</I>><i> +</I>><i> On 2013-10-30, at 7:58 AM, Daniel Goertzen wrote: +</I>><i> +</I>><i> > Well, this sort of works. I tried this in the response handler: +</I>><i> > +</I>><i> > {ok, Req2} = cowboy_req:reply(404, [] , <<"this is the body +</I>><i> that gets used">>, Req1), +</I>><i> > {<<"this body gets ignored">>, Req2, State}; +</I>><i> > +</I>><i> > +</I>><i> > +</I>><i> > The client receives a 404 response, but cowboy crashes: +</I>><i> > +</I>><i> > =ERROR REPORT==== 8-Sep-2013::22:22:03 === +</I>><i> > Error in process <0.131.0> with exit value: +</I>><i> {function_clause,[{cowboy_req,reply,[200,[],<<31 +</I>><i> bytes>>,{http_req,#Port<0.1208>,ranch_tcp,keepalive,<0.131.0>,<<3 +</I>><i> bytes>>,'HTTP/1.1',{{192,168,1,187},51017},<<12 bytes>>,undefined,80,<<24 +</I>><i> bytes>>,undefined,<<0 bytes>>,undefined,[{channel_num,3}],[{<<10 +</I>><i> bytes>>,<<11 bytes>>},{<<4 bytes>>,<<12 bytes>>},{<<6 bytes>>,<<3 +</I>><i> bytes>>}],[{<<17 bytes>>,undefined},{<<13 bytes>>,undefined},{<<19 +</I>><i> bytes>>,undefined},{<<8 bytes>>,undefined},{<<6 bytes>>,[... +</I>><i> > +</I>><i> > +</I>><i> > +</I>><i> > The issue is that the REST wrapper wants to do the cowboy_req:reply(), +</I>><i> and when we do the call we cause the wrapper's call to fail. +</I>><i> > +</I>><i> > Dan. +</I>><i> > +</I>><i> > +</I>><i> > +</I>><i> > On Tue, Oct 29, 2013 at 4:01 PM, Ivan uemlianin <<A HREF="https://lists.ninenines.eu/listinfo/extend">ivan at llaisdy.com</A>> +</I>><i> wrote: +</I>><i> > Sorry for terse but I only have a phone. Why can't you return a 404 +</I>><i> here? Using something like cowboy:reply(404, ... +</I>><i> > +</I>><i> > Ivan +</I>><i> > +</I>><i> > -- +</I>><i> > festina lente +</I>><i> > +</I>><i> > +</I>><i> > On 29 Oct 2013, at 21:25, Daniel Goertzen <<A HREF="https://lists.ninenines.eu/listinfo/extend">daniel.goertzen at gmail.com</A>> +</I>><i> wrote: +</I>><i> > +</I>><i> >> My situation is that I have a rest handler that may fail due to invalid +</I>><i> url segments. Example situation: +</I>><i> >> +</I>><i> >> +</I>><i> >> init(_Transport, _Req, _Opts) -> +</I>><i> >> {upgrade, protocol, cowboy_rest}. +</I>><i> >> +</I>><i> >> content_types_provided(Req, State) -> +</I>><i> >> {[{<<"application/json">>, get_json}], Req, State}. +</I>><i> >> +</I>><i> >> get_json(Req0, State) -> +</I>><i> >> {Params, Req1} = lists:mapfoldl(fun cowboy_req:binding/2, Req0, +</I>><i> [param1, param2, param3, ....]), +</I>><i> >> +</I>><i> >> case catch other_module:request(Params) of +</I>><i> >> {'EXIT', {badarg, _}} -> +</I>><i> >> hmmm, Params were bad and I would like to return a 404 code +</I>><i> now. +</I>><i> >> Result -> +</I>><i> >> {jiffy:encode(Result), Req1, State} +</I>><i> >> end. +</I>><i> >> +</I>><i> >> +</I>><i> >> +</I>><i> >> So I would like to return a 404 code when my underlying request +</I>><i> function fails, but it appears my choices are: +</I>><i> >> +</I>><i> >> - return a 200 (ok) response with data. +</I>><i> >> - crash and cause a 500 (Internal Server Error) response to be +</I>><i> returned. Not exactly the sentiment I want. +</I>><i> >> +</I>><i> >> +</I>><i> >> Is there some other way to cause a 404 response? +</I>><i> >> +</I>><i> >> I realize I could add path constraint functions, but I will be +</I>><i> replicating logic from my underlying request function. Furthermore, the +</I>><i> constraint functions consider parameters in isolation, so that won't work +</I>><i> if the validity of parameters is coupled. +</I>><i> >> +</I>><i> >> Thanks, +</I>><i> >> Dan. +</I>><i> >> _______________________________________________ +</I>><i> >> Extend mailing list +</I>><i> >> <A HREF="https://lists.ninenines.eu/listinfo/extend">Extend at lists.ninenines.eu</A> +</I>><i> >> <A HREF="http://lists.ninenines.eu:81/listinfo/extend">http://lists.ninenines.eu:81/listinfo/extend</A> +</I>><i> > +</I>><i> > _______________________________________________ +</I>><i> > Extend mailing list +</I>><i> > <A HREF="https://lists.ninenines.eu/listinfo/extend">Extend at lists.ninenines.eu</A> +</I>><i> > <A HREF="http://lists.ninenines.eu:81/listinfo/extend">http://lists.ninenines.eu:81/listinfo/extend</A> +</I>><i> +</I>><i> +</I>-------------- next part -------------- +An HTML attachment was scrubbed... +URL: <<A HREF="http://lists.ninenines.eu/archives/extend/attachments/20131030/3ea4ac64/attachment.html">http://lists.ninenines.eu/archives/extend/attachments/20131030/3ea4ac64/attachment.html</A>> +</PRE> + +<!--endarticle--> + <HR> + <P><UL> + <!--threads--> + <LI>Previous message: <A HREF="000290.html">[99s-extend] REST handler failure +</A></li> + <LI>Next message: <A HREF="000291.html">[99s-extend] REST handler failure +</A></li> + <LI> <B>Messages sorted by:</B> + <a href="date.html#293">[ date ]</a> + <a href="thread.html#293">[ thread ]</a> + <a href="subject.html#293">[ subject ]</a> + <a href="author.html#293">[ author ]</a> + </LI> + </UL> + +<hr> +<a href="https://lists.ninenines.eu/listinfo/extend">More information about the Extend +mailing list</a><br> +</body></html> |