aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_rest.erl
diff options
context:
space:
mode:
authorSteve Strong <[email protected]>2019-03-13 11:36:04 +0000
committerLoïc Hoguin <[email protected]>2019-04-03 13:54:32 +0200
commitbfee20e61e9f6f4ad2e2d39d68c9c94910c67bac (patch)
tree29b3cc7404dd55cbc05b9116da2c30c6046b8449 /src/cowboy_rest.erl
parentcd9b04792caabdcb901ea17a3fee0c2414d5ab98 (diff)
downloadcowboy-bfee20e61e9f6f4ad2e2d39d68c9c94910c67bac.tar.gz
cowboy-bfee20e61e9f6f4ad2e2d39d68c9c94910c67bac.tar.bz2
cowboy-bfee20e61e9f6f4ad2e2d39d68c9c94910c67bac.zip
Bind erlang:get_stacktrace prior to making other calls
If we bind too late there might be an exception triggered in the terminate function and we will not get the correct stacktrace as a result.
Diffstat (limited to 'src/cowboy_rest.erl')
-rw-r--r--src/cowboy_rest.erl3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/cowboy_rest.erl b/src/cowboy_rest.erl
index 010bf05..7be3e26 100644
--- a/src/cowboy_rest.erl
+++ b/src/cowboy_rest.erl
@@ -1622,8 +1622,9 @@ switch_handler({switch_handler, Mod, Opts}, Req, #state{handler_state=HandlerSta
-spec error_terminate(cowboy_req:req(), #state{}, atom(), any()) -> no_return().
error_terminate(Req, #state{handler=Handler, handler_state=HandlerState}, Class, Reason) ->
+ StackTrace = erlang:get_stacktrace(),
cowboy_handler:terminate({crash, Class, Reason}, Req, HandlerState, Handler),
- erlang:raise(Class, Reason, erlang:get_stacktrace()).
+ erlang:raise(Class, Reason, StackTrace).
terminate(Req, #state{handler=Handler, handler_state=HandlerState}) ->
Result = cowboy_handler:terminate(normal, Req, HandlerState, Handler),