2011-12-29 00:06:22 +01:00
|
|
|
%% Feel free to use, reuse and abuse the code in this file.
|
|
|
|
|
2013-04-24 20:28:44 +02:00
|
|
|
-module(http_errors).
|
2011-12-29 00:06:22 +01:00
|
|
|
|
2014-09-26 15:58:44 +03:00
|
|
|
-export([init/2]).
|
|
|
|
|
|
|
|
init(Req, _Opts) ->
|
2014-09-23 16:43:29 +03:00
|
|
|
#{'case' := Case} = cowboy_req:match_qs(Req, ['case']),
|
|
|
|
case_init(Case, Req).
|
2011-12-29 00:06:22 +01:00
|
|
|
|
|
|
|
case_init(<<"init_before_reply">> = Case, _Req) ->
|
2014-04-21 21:22:08 +02:00
|
|
|
cowboy_error_h:ignore(?MODULE, case_init, 2),
|
2014-09-24 15:07:59 +03:00
|
|
|
error(Case);
|
2011-12-29 00:06:22 +01:00
|
|
|
case_init(<<"init_after_reply">> = Case, Req) ->
|
2014-04-21 21:22:08 +02:00
|
|
|
cowboy_error_h:ignore(?MODULE, case_init, 2),
|
2014-09-23 16:43:29 +03:00
|
|
|
_ = cowboy_req:reply(200, [], "http_handler_crashes", Req),
|
2014-09-24 15:07:59 +03:00
|
|
|
error(Case).
|