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, json_body: { message: "Access denied" }) ⇒ Middleware

Returns a new instance of Middleware.

Raises:

  • (TypeError)


8
9
10
11
12
13
14
# File 'lib/rails/auth/error_page/middleware.rb', line 8

def initialize(app, page_body: nil, json_body: { message: "Access denied" })
  raise TypeError, "page_body must be a String" unless page_body.is_a?(String)

  @app       = app
  @page_body = page_body.freeze
  @json_body = json_body.to_json
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
# File 'lib/rails/auth/error_page/middleware.rb', line 16

def call(env)
  @app.call(env)
rescue Rails::Auth::NotAuthorizedError
  access_denied(env)
end