Class: DebugExceptionsJson

Inherits:
Object
  • Object
show all
Defined in:
lib/debug_exceptions_json.rb,
lib/debug_exceptions_json/version.rb,
lib/debug_exceptions_json/rspec/hook.rb,
lib/debug_exceptions_json/rspec/formatter.rb

Defined Under Namespace

Modules: RSpec

Constant Summary collapse

DEFAULT_BUILDER =
-> (exception, env) {
  [
    '500',
    { 'Content-Type' => 'application/json' },
    [
      {
        error: {
          exception_class: exception.class.name,
          message: exception.message,
          backtrace: exception.backtrace,
        },
      }.to_json
    ],
  ]
}
VERSION =
'0.2.6'

Instance Method Summary collapse

Constructor Details

#initialize(app, response_builder = DEFAULT_BUILDER) ⇒ DebugExceptionsJson

app - A rack app response_builder - A Proc which builds response

response_builder takes 2 parameters:

exception - An exception object
env - A Hash


28
29
30
31
# File 'lib/debug_exceptions_json.rb', line 28

def initialize(app, response_builder = DEFAULT_BUILDER)
  @app = app
  @response_builder = response_builder
end

Instance Method Details

#call(env) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/debug_exceptions_json.rb', line 33

def call(env)
  @app.call(env)
rescue Exception => exception
  raise exception unless show_exception?(env)
  raise exception unless response_with_json?(env)

  log_error(exception, env)
  @response_builder.call(exception, env)
end