Class: BetterErrors::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/better_errors/middleware.rb

Overview

Better Errors' error handling middleware. Including this in your middleware stack will show a Better Errors error page for exceptions raised below this middleware.

If you are using Ruby on Rails, you do not need to manually insert this middleware into your middleware stack.

Examples:

Sinatra

require "better_errors"

if development?
  use BetterErrors::Middleware
end

Rack

require "better_errors"
if ENV["RACK_ENV"] == "development"
  use BetterErrors::Middleware
end

Instance Method Summary collapse

Constructor Details

#initialize(app, handler = ErrorPage) ⇒ Middleware

A new instance of BetterErrors::Middleware

Parameters:

  • app

    The Rack app/middleware to wrap with Better Errors

  • handler (defaults to: ErrorPage)

    The error handler to use.



29
30
31
32
# File 'lib/better_errors/middleware.rb', line 29

def initialize(app, handler = ErrorPage)
  @app      = app
  @handler  = handler
end

Instance Method Details

#call(env) ⇒ Array

Calls the Better Errors middleware

Parameters:

  • env (Hash)

Returns:

  • (Array)


38
39
40
41
42
43
44
45
46
47
# File 'lib/better_errors/middleware.rb', line 38

def call(env)
  case env["PATH_INFO"]
  when %r{\A/__better_errors/(?<oid>-?\d+)/(?<method>\w+)\z}
    internal_call env, $~
  when %r{\A/__better_errors/?\z}
    show_error_page env
  else
    app_call env
  end
end