Exception: Oauth2ApiClient::ResponseError

Inherits:
Error
  • Object
show all
Defined in:
lib/oauth2_api_client/errors.rb

Constant Summary collapse

STATUSES =
{
  400 => "Bad Request",
  401 => "Unauthorized",
  402 => "Payment Required",
  403 => "Forbidden",
  404 => "Not Found",
  405 => "Method Not Allowed",
  406 => "Not Acceptable",
  407 => "Proxy Authentication Required",
  408 => "Request Timeout",
  409 => "Conflict",
  410 => "Gone",
  411 => "Length Required",
  412 => "Precondition Failed",
  413 => "Payload Too Large",
  414 => "URI Too Long",
  415 => "Unsupported Media Type",
  416 => "Range Not Satisfiable",
  417 => "Expectation Failed",
  418 => "I'm A Teapot",
  421 => "Too Many Connections From This IP",
  422 => "Unprocessable Entity",
  423 => "Locked",
  424 => "Failed Dependency",
  425 => "Unordered Collection",
  426 => "Upgrade Required",
  428 => "Precondition Required",
  429 => "Too Many Requests",
  431 => "Request Header Fields Too Large",
  449 => "Retry With",
  450 => "Blocked By Windows Parental Controls",

  500 => "Internal Server Error",
  501 => "Not Implemented",
  502 => "Bad Gateway",
  503 => "Service Unavailable",
  504 => "Gateway Timeout",
  505 => "HTTP Version Not Supported",
  506 => "Variant Also Negotiates",
  507 => "Insufficient Storage",
  508 => "Loop Detected",
  509 => "Bandwidth Limit Exceeded",
  510 => "Not Extended",
  511 => "Network Authentication Required"
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ResponseError

Returns a new instance of ResponseError.



69
70
71
72
73
# File 'lib/oauth2_api_client/errors.rb', line 69

def initialize(response)
  super()

  @response = response
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



67
68
69
# File 'lib/oauth2_api_client/errors.rb', line 67

def response
  @response
end

Class Method Details

.const_name(message) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a sanitized version to be used as a constant name for a given http error message.



94
95
96
# File 'lib/oauth2_api_client/errors.rb', line 94

def self.const_name(message)
  message.gsub(/[^a-zA-Z0-9]/, "")
end

.for(response) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the exception class for a status code of the given response.



83
84
85
86
87
# File 'lib/oauth2_api_client/errors.rb', line 83

def self.for(response)
  return const_get(const_name(STATUSES[response.code])).new(response) if STATUSES.key?(response.code)

  new(response)
end

Instance Method Details

#to_sObject



75
76
77
# File 'lib/oauth2_api_client/errors.rb', line 75

def to_s
  "#{self.class.name} (#{response.code}, #{response.uri}): #{response.body}"
end