Exception: Safire::Errors::OAuthError Abstract
- Defined in:
- lib/safire/errors.rb
Overview
Base class for OAuth 2.0 protocol errors returned by the authorization server.
Provides a shared structure for errors that originate from HTTP interactions with OAuth 2.0 endpoints (token, authorization, registration). Subclasses define #operation_label to set the lead phrase of the error message and may override #build_message to handle structural failure paths (e.g. a valid HTTP response that is missing a required field such as access_token or client_id).
Can be used as a single rescue point for any server-side OAuth protocol failure:
rescue Safire::Errors::OAuthError => e
Direct Known Subclasses
Instance Attribute Summary collapse
-
#error_code ⇒ String?
readonly
OAuth2
errorfield (e.g. “invalid_grant”). -
#error_description ⇒ String?
readonly
OAuth2
error_descriptionfield. -
#status ⇒ Integer?
readonly
HTTP status code.
Instance Method Summary collapse
-
#initialize(status: nil, error_code: nil, error_description: nil) ⇒ OAuthError
constructor
A new instance of OAuthError.
Constructor Details
#initialize(status: nil, error_code: nil, error_description: nil) ⇒ OAuthError
Returns a new instance of OAuthError.
133 134 135 136 137 138 |
# File 'lib/safire/errors.rb', line 133 def initialize(status: nil, error_code: nil, error_description: nil) @status = status @error_code = error_code @error_description = error_description super() end |
Instance Attribute Details
#error_code ⇒ String? (readonly)
Returns OAuth2 error field (e.g. “invalid_grant”).
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/safire/errors.rb', line 130 class OAuthError < Error attr_reader :status, :error_code, :error_description def initialize(status: nil, error_code: nil, error_description: nil) @status = status @error_code = error_code @error_description = error_description super() end private # @abstract Subclasses must define this to set the lead phrase of the error message. def operation_label raise NotImplementedError, "#{self.class} must define #operation_label" end def parts = [operation_label] parts << "HTTP #{@status}" if @status parts << @error_code if @error_code parts << @error_description if @error_description parts.join(' — ') end end |
#error_description ⇒ String? (readonly)
Returns OAuth2 error_description field.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/safire/errors.rb', line 130 class OAuthError < Error attr_reader :status, :error_code, :error_description def initialize(status: nil, error_code: nil, error_description: nil) @status = status @error_code = error_code @error_description = error_description super() end private # @abstract Subclasses must define this to set the lead phrase of the error message. def operation_label raise NotImplementedError, "#{self.class} must define #operation_label" end def parts = [operation_label] parts << "HTTP #{@status}" if @status parts << @error_code if @error_code parts << @error_description if @error_description parts.join(' — ') end end |
#status ⇒ Integer? (readonly)
Returns HTTP status code.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/safire/errors.rb', line 130 class OAuthError < Error attr_reader :status, :error_code, :error_description def initialize(status: nil, error_code: nil, error_description: nil) @status = status @error_code = error_code @error_description = error_description super() end private # @abstract Subclasses must define this to set the lead phrase of the error message. def operation_label raise NotImplementedError, "#{self.class} must define #operation_label" end def parts = [operation_label] parts << "HTTP #{@status}" if @status parts << @error_code if @error_code parts << @error_description if @error_description parts.join(' — ') end end |