Class: Rails::Auth::ErrorPage::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/auth/error_page/middleware.rb

Overview

Render an error page in the event Rails::Auth::NotAuthorizedError is raised

Instance Method Summary collapse

Constructor Details

#initialize(app, page_body: nil) ⇒ Middleware

Returns a new instance of Middleware.

Raises:

  • (TypeError)


6
7
8
9
10
11
# File 'lib/rails/auth/error_page/middleware.rb', line 6

def initialize(app, page_body: nil)
  raise TypeError, "page_body must be a String" unless page_body.is_a?(String)

  @app       = app
  @page_body = page_body.freeze
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
# File 'lib/rails/auth/error_page/middleware.rb', line 13

def call(env)
  @app.call(env)
rescue Rails::Auth::NotAuthorizedError
  [403, {}, [@page_body]]
end