mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-16 05:00:24 +00:00
Remove the error tuple return value for middlewares
It wasn't interesting compared to simply returning a halt tuple with an explicit reply.
This commit is contained in:
parent
aa4d86b81f
commit
c56bada509
8 changed files with 8 additions and 31 deletions
|
@ -99,7 +99,6 @@ handler_init(Req, State, Handler, HandlerOpts) ->
|
|||
-> {ok, Req, Env}
|
||||
| {suspend, module(), atom(), any()}
|
||||
| {halt, Req}
|
||||
| {error, cowboy:http_status(), Req}
|
||||
when Req::cowboy_req:req(), Env::cowboy_middleware:env().
|
||||
upgrade_protocol(Req, #state{env=Env},
|
||||
Handler, HandlerOpts, Module) ->
|
||||
|
|
|
@ -21,5 +21,4 @@
|
|||
-> {ok, Req, Env}
|
||||
| {suspend, module(), atom(), [any()]}
|
||||
| {halt, Req}
|
||||
| {error, cowboy:http_status(), Req}
|
||||
when Req::cowboy_req:req(), Env::env().
|
||||
|
|
|
@ -428,9 +428,7 @@ execute(Req, State, Env, [Middleware|Tail]) ->
|
|||
erlang:hibernate(?MODULE, resume,
|
||||
[State, Env, Tail, Module, Function, Args]);
|
||||
{halt, Req2} ->
|
||||
next_request(Req2, State, ok);
|
||||
{error, Code, Req2} ->
|
||||
error_terminate(Code, Req2, State)
|
||||
next_request(Req2, State, ok)
|
||||
end.
|
||||
|
||||
-spec resume(#state{}, cowboy_middleware:env(), [module()],
|
||||
|
@ -443,9 +441,7 @@ resume(State, Env, Tail, Module, Function, Args) ->
|
|||
erlang:hibernate(?MODULE, resume,
|
||||
[State, Env, Tail, Module2, Function2, Args2]);
|
||||
{halt, Req2} ->
|
||||
next_request(Req2, State, ok);
|
||||
{error, Code, Req2} ->
|
||||
error_terminate(Code, Req2, State)
|
||||
next_request(Req2, State, ok)
|
||||
end.
|
||||
|
||||
-spec next_request(cowboy_req:req(), #state{}, any()) -> ok.
|
||||
|
|
|
@ -157,7 +157,7 @@ compile_brackets_split(<< C, Rest/binary >>, Acc, N) ->
|
|||
compile_brackets_split(Rest, << Acc/binary, C >>, N).
|
||||
|
||||
-spec execute(Req, Env)
|
||||
-> {ok, Req, Env} | {error, 400 | 404, Req}
|
||||
-> {ok, Req, Env} | {halt, Req}
|
||||
when Req::cowboy_req:req(), Env::cowboy_middleware:env().
|
||||
execute(Req, Env) ->
|
||||
{_, Dispatch} = lists:keyfind(dispatch, 1, Env),
|
||||
|
@ -168,11 +168,11 @@ execute(Req, Env) ->
|
|||
Req2 = cowboy_req:set_bindings(HostInfo, PathInfo, Bindings, Req),
|
||||
{ok, Req2, [{handler, Handler}, {handler_opts, HandlerOpts}|Env]};
|
||||
{error, notfound, host} ->
|
||||
{error, 400, Req};
|
||||
{halt, cowboy_req:reply(400, Req)};
|
||||
{error, badrequest, path} ->
|
||||
{error, 400, Req};
|
||||
{halt, cowboy_req:reply(400, Req)};
|
||||
{error, notfound, path} ->
|
||||
{error, 404, Req}
|
||||
{halt, cowboy_req:reply(404, Req)}
|
||||
end.
|
||||
|
||||
%% Internal.
|
||||
|
|
|
@ -407,9 +407,7 @@ execute(Req, Env, [Middleware|Tail]) ->
|
|||
erlang:hibernate(?MODULE, resume,
|
||||
[Env, Tail, Module, Function, Args]);
|
||||
{halt, Req2} ->
|
||||
cowboy_req:ensure_response(Req2, 204);
|
||||
{error, Status, Req2} ->
|
||||
cowboy_req:reply(Status, Req2)
|
||||
cowboy_req:ensure_response(Req2, 204)
|
||||
end.
|
||||
|
||||
-spec resume(cowboy_middleware:env(), [module()],
|
||||
|
@ -422,9 +420,7 @@ resume(Env, Tail, Module, Function, Args) ->
|
|||
erlang:hibernate(?MODULE, resume,
|
||||
[Env, Tail, Module2, Function2, Args2]);
|
||||
{halt, Req2} ->
|
||||
cowboy_req:ensure_response(Req2, 204);
|
||||
{error, Status, Req2} ->
|
||||
cowboy_req:reply(Status, Req2)
|
||||
cowboy_req:ensure_response(Req2, 204)
|
||||
end.
|
||||
|
||||
%% Reply functions used by cowboy_req.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue