Sha256: 81742ef5b8474c843cda2748d5d247f335682b58138b9e571f8df9b609b73d7a

Contents?: true

Size: 566 Bytes

Versions: 5

Compression:

Stored size: 566 Bytes

Contents

module Rails
  module Auth
    module ErrorPage
      # Render an error page in the event Rails::Auth::NotAuthorizedError is raised
      class Middleware
        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

        def call(env)
          @app.call(env)
        rescue Rails::Auth::NotAuthorizedError
          [403, { "Content-Type" => "text/html" }, [@page_body]]
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rails-auth-1.2.0 lib/rails/auth/error_page/middleware.rb
rails-auth-1.1.0 lib/rails/auth/error_page/middleware.rb
rails-auth-1.0.0 lib/rails/auth/error_page/middleware.rb
rails-auth-0.5.3 lib/rails/auth/error_page/middleware.rb
rails-auth-0.5.2 lib/rails/auth/error_page/middleware.rb