Exception: OAuth2::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/oauth2/error.rb

Overview

Represents an OAuth2 error condition.

Wraps details from an OAuth2::Response or Hash payload returned by an authorization server, exposing error code and description per RFC 6749.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Error

Create a new OAuth2::Error

Parameters:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/oauth2/error.rb', line 18

def initialize(response)
  @response = response
  if response.respond_to?(:parsed)
    if response.parsed.is_a?(Hash)
      @code = response.parsed["error"]
      @description = response.parsed["error_description"]
    end
  elsif response.is_a?(Hash)
    @code = response["error"]
    @description = response["error_description"]
  end
  @body = if response.respond_to?(:body)
    response.body
  else
    @response
  end
  message_opts = parse_error_description(@code, @description)
  super(error_message(@body, message_opts))
end

Instance Attribute Details

#bodyOAuth2::Response, ... (readonly)

Returns:

  • (OAuth2::Response, Hash, Object)

    Original response or payload used to build the error

  • (String)

    Raw body content (if available)

  • (String, nil)

    Error code (e.g., ‘invalid_grant’)

  • (String, nil)

    Human-readable description for the error



13
14
15
# File 'lib/oauth2/error.rb', line 13

def body
  @body
end

#codeOAuth2::Response, ... (readonly)

Returns:

  • (OAuth2::Response, Hash, Object)

    Original response or payload used to build the error

  • (String)

    Raw body content (if available)

  • (String, nil)

    Error code (e.g., ‘invalid_grant’)

  • (String, nil)

    Human-readable description for the error



13
14
15
# File 'lib/oauth2/error.rb', line 13

def code
  @code
end

#descriptionOAuth2::Response, ... (readonly)

Returns:

  • (OAuth2::Response, Hash, Object)

    Original response or payload used to build the error

  • (String)

    Raw body content (if available)

  • (String, nil)

    Error code (e.g., ‘invalid_grant’)

  • (String, nil)

    Human-readable description for the error



13
14
15
# File 'lib/oauth2/error.rb', line 13

def description
  @description
end

#responseOAuth2::Response, ... (readonly)

Returns:

  • (OAuth2::Response, Hash, Object)

    Original response or payload used to build the error

  • (String)

    Raw body content (if available)

  • (String, nil)

    Error code (e.g., ‘invalid_grant’)

  • (String, nil)

    Human-readable description for the error



13
14
15
# File 'lib/oauth2/error.rb', line 13

def response
  @response
end