Exception: OAuth2::Error — Documentation by YARD 0.9.45

# Exception: OAuth2::Error

Inherits:
  StandardError
  - Object
  - StandardError
  - OAuth2::Error
  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

- #body ⇒ OAuth2::Response, ... readonly
- #code ⇒ OAuth2::Response, ... readonly
- #description ⇒ OAuth2::Response, ... readonly
- #response ⇒ OAuth2::Response, ... readonly

## Instance Method Summary collapse

- #initialize(response) ⇒ Error constructor

  Create a new OAuth2::Error.

## Constructor Details

### #initialize(response) ⇒ `Error`

Create a new OAuth2::Error

Parameters:

- response (`OAuth2::Response`, `Hash`, `Object`) —

  A Response or error payload

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

    def initialize(response)
      @response = response
      @code = nil
      @description = nil
      if response.respond_to?(:parsed)
        parsed_response = response.parsed
        if parsed_response.is_a?(Hash)
          @code = parsed_response["error"]
          @description = parsed_response["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

### #body ⇒ `OAuth2::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

### #code ⇒ `OAuth2::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

### #description ⇒ `OAuth2::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

### #response ⇒ `OAuth2::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