Exception: OAuth2::Error

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Error

standard error values include: :invalid_request, :invalid_client, :invalid_token, :invalid_grant, :unsupported_grant_type, :invalid_scope



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/oauth2/error.rb', line 7

def initialize(response)
  response.error = self
  @response = response

  if response.parsed.is_a?(Hash)
    @code = response.parsed['error']
    @description = response.parsed['error_description']
    error_description = "#{@code}: #{@description}"
  end

  super(error_message(response.body, :error_description => error_description))
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code



3
4
5
# File 'lib/oauth2/error.rb', line 3

def code
  @code
end

#descriptionObject (readonly)

Returns the value of attribute description



3
4
5
# File 'lib/oauth2/error.rb', line 3

def description
  @description
end

#responseObject (readonly)

Returns the value of attribute response



3
4
5
# File 'lib/oauth2/error.rb', line 3

def response
  @response
end

Instance Method Details

#error_message(response_body, opts = {}) ⇒ Object

Makes a error message



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

def error_message(response_body, opts = {})
  message = []

  opts[:error_description] && message << opts[:error_description]

  error_message = if opts[:error_description] && opts[:error_description].respond_to?(:encoding)
                    script_encoding = opts[:error_description].encoding
                    response_body.encode(script_encoding, :invalid => :replace, :undef => :replace)
                  else
                    response_body
                  end

  message << error_message

  message.join("\n")
end