Class: BetterErrors::Middleware
- Inherits:
-
Object
- Object
- BetterErrors::Middleware
- 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.
Constant Summary collapse
- ALLOWED_IPS =
The set of IP addresses that are allowed to access Better Errors.
Set to
{ "127.0.0.1/8", "::1/128" }
by default. Set.new
Class Method Summary collapse
-
.allow_ip!(addr) ⇒ Object
Adds an address to the set of IP addresses allowed to access Better Errors.
Instance Method Summary collapse
-
#call(env) ⇒ Array
Calls the Better Errors middleware.
-
#initialize(app, handler = ErrorPage) ⇒ Middleware
constructor
A new instance of BetterErrors::Middleware.
Constructor Details
#initialize(app, handler = ErrorPage) ⇒ Middleware
A new instance of BetterErrors::Middleware
45 46 47 48 |
# File 'lib/better_errors/middleware.rb', line 45 def initialize(app, handler = ErrorPage) @app = app @handler = handler end |
Class Method Details
.allow_ip!(addr) ⇒ Object
Adds an address to the set of IP addresses allowed to access Better Errors.
34 35 36 |
# File 'lib/better_errors/middleware.rb', line 34 def self.allow_ip!(addr) ALLOWED_IPS << IPAddr.new(addr) end |
Instance Method Details
#call(env) ⇒ Array
Calls the Better Errors middleware
54 55 56 57 58 59 60 |
# File 'lib/better_errors/middleware.rb', line 54 def call(env) if allow_ip? env better_errors_call env else @app.call env end end |