Class: Tidewave::ExceptionsMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/tidewave/exceptions_middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ExceptionsMiddleware



4
5
6
# File 'lib/tidewave/exceptions_middleware.rb', line 4

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/tidewave/exceptions_middleware.rb', line 8

def call(env)
  request = ActionDispatch::Request.new(env)
  status, headers, body = @app.call(env)

  exception = request.get_header("tidewave.exception")

  if exception
    formatted = format_exception_html(exception, request)
    body, headers = append_body(body, headers, formatted)
  end

  [ status, headers, body ]
rescue => error
  Rails.logger.error("Failure in Tidewave::ExceptionsMiddleware, message: #{error.message}")
  raise error
end