Exception: SimpleOAuth::OAuth2::Error
- Defined in:
- lib/simple_oauth/oauth2/error.rb,
sig/simple_oauth/oauth2.rbs
Overview
Error returned by an OAuth 2.0 endpoint
Constant Summary collapse
- INVALID_STATUS =
The error message for a status that is not an HTTP status
"The status must be an Integer or a String of digits"
Instance Attribute Summary collapse
-
#code ⇒ String?
readonly
The error code, such as invalid_grant, if the response included one.
-
#description ⇒ String?
readonly
The human-readable description from the endpoint.
-
#status ⇒ Integer?
readonly
The HTTP status of the response.
-
#uri ⇒ String?
readonly
The URI of a page describing the error.
Class Method Summary collapse
-
.from_response(status:, body:) ⇒ Error
Build the error described by an OAuth 2.0 error response.
-
.http_status(value) ⇒ Integer
private
The HTTP status of a response, as an Integer.
Instance Method Summary collapse
-
#initialize(code:, description: nil, uri: nil, status: nil) ⇒ Error
constructor
Initialize a new error.
Constructor Details
#initialize(code:, description: nil, uri: nil, status: nil) ⇒ Error
Initialize a new error
85 86 87 88 89 90 91 92 |
# File 'lib/simple_oauth/oauth2/error.rb', line 85 def initialize(code:, description: nil, uri: nil, status: nil) @code = code @description = description @uri = uri @status = status details = [code, description].compact super(details.empty? ? "OAuth 2.0 request failed with status #{status}" : details.join(": ")) end |
Instance Attribute Details
#code ⇒ String? (readonly)
The error code, such as invalid_grant, if the response included one
23 24 25 |
# File 'lib/simple_oauth/oauth2/error.rb', line 23 def code @code end |
#description ⇒ String? (readonly)
The human-readable description from the endpoint
31 32 33 |
# File 'lib/simple_oauth/oauth2/error.rb', line 31 def description @description end |
#status ⇒ Integer? (readonly)
The HTTP status of the response
47 48 49 |
# File 'lib/simple_oauth/oauth2/error.rb', line 47 def status @status end |
#uri ⇒ String? (readonly)
The URI of a page describing the error
39 40 41 |
# File 'lib/simple_oauth/oauth2/error.rb', line 39 def uri @uri end |
Class Method Details
.from_response(status:, body:) ⇒ Error
Build the error described by an OAuth 2.0 error response
70 71 72 73 74 |
# File 'lib/simple_oauth/oauth2/error.rb', line 70 def self.from_response(status:, body:) params = ResponseBody.parse(body) new(code: params["error"], description: params["error_description"], uri: params["error_uri"], status: http_status(status)) end |
.http_status(value) ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The HTTP status of a response, as an Integer
57 58 59 |
# File 'lib/simple_oauth/oauth2/error.rb', line 57 def self.http_status(value) Integer(value, exception: false) || raise(ArgumentError, "#{INVALID_STATUS}: #{value.inspect}") end |