Module: RestGraph::Error::Util

Extended by:
Util
Included in:
RestGraph::Error, Util
Defined in:
lib/rest-graph/core.rb

Instance Method Summary collapse

Instance Method Details

#invalid_token?(error) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
73
74
# File 'lib/rest-graph/core.rb', line 70

def invalid_token? error
  (%w[OAuthInvalidTokenException
      OAuthException].include?((error['error'] || {})['type'])) ||
  (error['error_code'] == 190) # Invalid OAuth 2.0 Access Token
end

#missing_token?(error) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
79
# File 'lib/rest-graph/core.rb', line 76

def missing_token? error
  (error['error'] || {})['message'] =~ /^An active access token/ ||
  (error['error_code'] == 104) # Requires valid signature
end

#parse(error, url = '') ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/rest-graph/core.rb', line 59

def parse error, url=''
  return Error.new(error, url) unless error.kind_of?(Hash)
  if    invalid_token?(error)
    InvalidAccessToken.new(error, url)
  elsif missing_token?(error)
    MissingAccessToken.new(error, url)
  else
    Error.new(error, url)
  end
end