Class: Verikloak::Rails::ErrorRenderer
- Inherits:
-
Object
- Object
- Verikloak::Rails::ErrorRenderer
- Defined in:
- lib/verikloak/rails/error_renderer.rb
Overview
Renders JSON errors for authentication/authorization failures.
When status is 401, adds a ‘WWW-Authenticate: Bearer` header including `error` and `error_description` fields when available.
Header sanitization is delegated to ErrorResponse to ensure consistent control-character stripping across all Verikloak gems.
Constant Summary collapse
- DEFAULT_STATUS_MAP =
{ 'invalid_token' => 401, 'unauthorized' => 401, 'forbidden' => 403, 'jwks_fetch_failed' => 503, 'jwks_parse_failed' => 503, 'discovery_metadata_fetch_failed' => 503, 'discovery_metadata_invalid' => 503, # Additional infrastructure/configuration errors from core 'invalid_discovery_url' => 503, 'discovery_redirect_error' => 503 }.freeze
Instance Method Summary collapse
-
#render(controller, error) ⇒ void
Render an error as JSON, adding ‘WWW-Authenticate` when appropriate.
Instance Method Details
#render(controller, error) ⇒ void
This method returns an undefined value.
Render an error as JSON, adding ‘WWW-Authenticate` when appropriate.
39 40 41 42 43 44 45 46 |
# File 'lib/verikloak/rails/error_renderer.rb', line 39 def render(controller, error) code, = (error) status = status_for(error, code) auth_headers(status, code, ).each do |header, value| controller.response.set_header(header, value) end controller.render json: { error: code || 'unauthorized', message: }, status: status end |