Skip to content

Commit

Permalink
Use top-level rescue
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrudel committed Jun 19, 2024
1 parent b62a7eb commit 87c281f
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions lib/bandit/http2/handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,24 @@ defmodule Bandit.HTTP2.Handler do

@impl ThousandIsland.Handler
def handle_connection(socket, state) do
try do
connection = Bandit.HTTP2.Connection.init(socket, state.plug, state.opts)
{:continue, Map.merge(state, %{buffer: <<>>, connection: connection})}
rescue
error ->
case Keyword.get(state.opts.http, :log_protocol_errors, :short) do
:short ->
Logger.error(Exception.format_banner(:error, error, __STACKTRACE__),
domain: [:bandit]
)

:verbose ->
Logger.error(Exception.format(:error, error, __STACKTRACE__), domain: [:bandit])

false ->
:ok
end

{:close, state}
end
connection = Bandit.HTTP2.Connection.init(socket, state.plug, state.opts)
{:continue, Map.merge(state, %{buffer: <<>>, connection: connection})}
rescue
error ->
case Keyword.get(state.opts.http, :log_protocol_errors, :short) do
:short ->
Logger.error(Exception.format_banner(:error, error, __STACKTRACE__),
domain: [:bandit]
)

:verbose ->
Logger.error(Exception.format(:error, error, __STACKTRACE__), domain: [:bandit])

false ->
:ok
end

{:close, state}
end

@impl ThousandIsland.Handler
Expand Down

0 comments on commit 87c281f

Please sign in to comment.