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)


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

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



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

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