From 271869889587085494baaedc6b44e939252637f0 Mon Sep 17 00:00:00 2001 From: James Fish Date: Wed, 6 May 2015 16:21:14 +0100 Subject: Exit with exit/1 on handler exception and include class in reason --- src/cowboy_handler.erl | 10 ++++++---- src/cowboy_loop.erl | 5 +++-- src/cowboy_rest.erl | 5 +++-- src/cowboy_websocket.erl | 5 +++-- 4 files changed, 15 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/cowboy_handler.erl b/src/cowboy_handler.erl index e3faf66..952c238 100644 --- a/src/cowboy_handler.erl +++ b/src/cowboy_handler.erl @@ -52,13 +52,14 @@ execute(Req, Env) -> Stacktrace = erlang:get_stacktrace(), cowboy_req:maybe_reply(Stacktrace, Req), terminate({crash, Class, Reason}, Req, HandlerOpts, Handler), - erlang:Class([ + exit({cowboy_handler, [ + {class, Class}, {reason, Reason}, {mfa, {Handler, init, 2}}, {stacktrace, Stacktrace}, {req, cowboy_req:to_list(Req)}, {opts, HandlerOpts} - ]) + ]}) end. -spec terminate(any(), Req, any(), module()) -> ok when Req::cowboy_req:req(). @@ -68,14 +69,15 @@ terminate(Reason, Req, State, Handler) -> try Handler:terminate(Reason, cowboy_req:lock(Req), State) catch Class:Reason2 -> - erlang:Class([ + exit({cowboy_handler, [ + {class, Class}, {reason, Reason2}, {mfa, {Handler, terminate, 3}}, {stacktrace, erlang:get_stacktrace()}, {req, cowboy_req:to_list(Req)}, {state, State}, {terminate_reason, Reason} - ]) + ]}) end; false -> ok diff --git a/src/cowboy_loop.erl b/src/cowboy_loop.erl index 8920299..f0b2886 100644 --- a/src/cowboy_loop.erl +++ b/src/cowboy_loop.erl @@ -161,13 +161,14 @@ call(Req, State=#state{resp_sent=RespSent}, cowboy_req:maybe_reply(Stacktrace, Req) end, cowboy_handler:terminate({crash, Class, Reason}, Req, HandlerState, Handler), - erlang:Class([ + exit({cowboy_handler, [ + {class, Class}, {reason, Reason}, {mfa, {Handler, info, 3}}, {stacktrace, Stacktrace}, {req, cowboy_req:to_list(Req)}, {state, HandlerState} - ]) + ]}) end. %% It is sometimes important to make a socket passive as it was initially diff --git a/src/cowboy_rest.erl b/src/cowboy_rest.erl index 1a478a1..cf24050 100644 --- a/src/cowboy_rest.erl +++ b/src/cowboy_rest.erl @@ -977,13 +977,14 @@ error_terminate(Req, #state{handler=Handler, handler_state=HandlerState}, Stacktrace = erlang:get_stacktrace(), cowboy_req:maybe_reply(Stacktrace, Req), cowboy_handler:terminate({crash, Class, Reason}, Req, HandlerState, Handler), - erlang:Class([ + exit({cowboy_handler, [ + {class, Class}, {reason, Reason}, {mfa, {Handler, Callback, 2}}, {stacktrace, Stacktrace}, {req, cowboy_req:to_list(Req)}, {state, HandlerState} - ]). + ]}). terminate(Req, #state{env=Env, handler=Handler, handler_state=HandlerState}) -> Result = cowboy_handler:terminate(normal, Req, HandlerState, Handler), diff --git a/src/cowboy_websocket.erl b/src/cowboy_websocket.erl index 9ce4f9d..12728d0 100644 --- a/src/cowboy_websocket.erl +++ b/src/cowboy_websocket.erl @@ -350,14 +350,15 @@ handler_call(State=#state{handler=Handler}, Req, HandlerState, websocket_close(State, Req2, HandlerState2, stop) catch Class:Reason -> _ = websocket_close(State, Req, HandlerState, {crash, Class, Reason}), - erlang:Class([ + exit({cowboy_handler, [ + {class, Class}, {reason, Reason}, {mfa, {Handler, Callback, 3}}, {stacktrace, erlang:get_stacktrace()}, {msg, Message}, {req, cowboy_req:to_list(Req)}, {state, HandlerState} - ]) + ]}) end. -spec websocket_send(cow_ws:frame(), #state{}) -> ok | stop | {error, atom()}. -- cgit v1.2.3