class OAuth2::Error
Attributes
Public Class Methods
Source
# File lib/oauth2/error.rb 10 def initialize(response) 11 @response = response 12 if response.respond_to?(:parsed) 13 if response.parsed.is_a?(Hash) 14 @code = response.parsed["error"] 15 @description = response.parsed["error_description"] 16 end 17 elsif response.is_a?(Hash) 18 @code = response["error"] 19 @description = response["error_description"] 20 end 21 @body = if response.respond_to?(:body) 22 response.body 23 else 24 @response 25 end 26 message_opts = parse_error_description(@code, @description) 27 super(error_message(@body, message_opts)) 28 end
standard error codes include: ‘invalid_request’, ‘invalid_client’, ‘invalid_token’, ‘invalid_grant’, ‘unsupported_grant_type’, ‘invalid_scope’ response might be a Response
object, or the response.parsed hash
Calls superclass method
Private Instance Methods
Source
# File lib/oauth2/error.rb 32 def error_message(response_body, opts = {}) 33 lines = [] 34 35 lines << opts[:error_description] if opts[:error_description] 36 37 error_string = if response_body.respond_to?(:encode) && opts[:error_description].respond_to?(:encoding) 38 script_encoding = opts[:error_description].encoding 39 response_body.encode(script_encoding, invalid: :replace, undef: :replace) 40 else 41 response_body 42 end 43 44 lines << error_string 45 46 lines.join("\n") 47 end
Source
# File lib/oauth2/error.rb 49 def parse_error_description(code, description) 50 return {} unless code || description 51 52 error_description = "" 53 error_description += "#{code}: " if code 54 error_description += description if description 55 56 {error_description: error_description} 57 end