aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_handler.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2016-08-10 17:45:28 +0200
committerLoïc Hoguin <[email protected]>2016-08-10 17:45:28 +0200
commit9966df9ad4ddf74111d8cbffb6658497319a89b4 (patch)
treefdf6385e2f53465e2c6e9d2aef7d13e53301ed68 /src/cowboy_handler.erl
parente30d120bd8c9a4a7b469937d5b5be6a8dfe148d4 (diff)
downloadcowboy-9966df9ad4ddf74111d8cbffb6658497319a89b4.tar.gz
cowboy-9966df9ad4ddf74111d8cbffb6658497319a89b4.tar.bz2
cowboy-9966df9ad4ddf74111d8cbffb6658497319a89b4.zip
Let the stream handler take care of crash handling and logging
Diffstat (limited to 'src/cowboy_handler.erl')
-rw-r--r--src/cowboy_handler.erl5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/cowboy_handler.erl b/src/cowboy_handler.erl
index 7fb2dd5..af21342 100644
--- a/src/cowboy_handler.erl
+++ b/src/cowboy_handler.erl
@@ -36,7 +36,7 @@
-spec execute(Req, Env) -> {ok, Req, Env}
when Req::cowboy_req:req(), Env::cowboy_middleware:env().
execute(Req, Env=#{handler := Handler, handler_opts := HandlerOpts}) ->
- case Handler:init(Req, HandlerOpts) of
+ try Handler:init(Req, HandlerOpts) of
{ok, Req2, State} ->
Result = terminate(normal, Req2, State, Handler),
{ok, Req2, [{result, Result}|Env]};
@@ -48,6 +48,9 @@ execute(Req, Env=#{handler := Handler, handler_opts := HandlerOpts}) ->
Mod:upgrade(Req2, Env, Handler, State, Timeout, run);
{Mod, Req2, State, Timeout, hibernate} ->
Mod:upgrade(Req2, Env, Handler, State, Timeout, hibernate)
+ catch Class:Reason ->
+ terminate({crash, Class, Reason}, Req, HandlerOpts, Handler),
+ erlang:raise(Class, Reason, erlang:get_stacktrace())
end.
-spec terminate(any(), Req, any(), module()) -> ok when Req::cowboy_req:req().