Exception: EpoOps::Error

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

Constant Summary collapse

ClientError =

Raised when EPO returns a 4xx HTTP status code

Class.new(self)
BadRequest =

Raised when EPO returns the HTTP status code 400

Class.new(ClientError)
Unauthorized =

Raised when EPO returns the HTTP status code 401

Class.new(ClientError)
Forbidden =

Raised when EPO returns the HTTP status code 403

Class.new(ClientError)
NotFound =

Raised when EPO returns the HTTP status code 404

Class.new(ClientError)
NotAcceptable =

Raised when EPO returns the HTTP status code 406

Class.new(ClientError)
UnprocessableEntity =

Raised when EPO returns the HTTP status code 422

Class.new(ClientError)
TooManyRequests =

Raised when EPO returns the HTTP status code 429

Class.new(ClientError)
ServerError =

Raised when EPO returns a 5xx HTTP status code

Class.new(self)
InternalServerError =

Raised when EPO returns the HTTP status code 500

Class.new(ServerError)
BadGateway =

Raised when EPO returns the HTTP status code 502

Class.new(ServerError)
ServiceUnavailable =

Raised when EPO returns the HTTP status code 503

Class.new(ServerError)
GatewayTimeout =

Raised when EPO returns the HTTP status code 504

Class.new(ServerError)
AccessTokenExpired =

AccessToken has expired

Class.new(ClientError)
ERRORS =
{
  400 => EpoOps::Error::BadRequest,
  401 => EpoOps::Error::Unauthorized,
  403 => EpoOps::Error::Forbidden,
  404 => EpoOps::Error::NotFound,
  406 => EpoOps::Error::NotAcceptable,
  422 => EpoOps::Error::UnprocessableEntity,
  429 => EpoOps::Error::TooManyRequests,
  500 => EpoOps::Error::InternalServerError,
  502 => EpoOps::Error::BadGateway,
  503 => EpoOps::Error::ServiceUnavailable,
  504 => EpoOps::Error::GatewayTimeout
}.freeze
FORBIDDEN_MESSAGES =
{
  'This request has been rejected due to the violation of Fair Use policy' => EpoOps::Error::TooManyRequests
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = '', rate_limit = {}, code = nil) ⇒ Error

Returns a new instance of Error.



79
80
81
82
83
# File 'lib/epo_ops/error.rb', line 79

def initialize(message = '', rate_limit = {}, code = nil)
  super(message)
  @code = code
  @rate_limit = RateLimit.new(rate_limit)
end

Instance Attribute Details

#codeInteger (readonly)

Returns:

  • (Integer)


4
5
6
# File 'lib/epo_ops/error.rb', line 4

def code
  @code
end

#rate_limitInteger (readonly)

Returns:

  • (Integer)


4
5
6
# File 'lib/epo_ops/error.rb', line 4

def rate_limit
  @rate_limit
end

Class Method Details

.from_response(response) ⇒ Error

Parses an error from the given response

Returns:



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/epo_ops/error.rb', line 55

def from_response(response)
  code = response.status
  message = parse_error(response.parsed)

  if code == 403 && FORBIDDEN_MESSAGES[message]
    FORBIDDEN_MESSAGES[message].new(message, response.headers, code)
  elsif code == 400 && response.headers['www-authenticate'] && response.headers['www-authenticate'].include?('Access Token expired')
    Error::AccessTokenExpired.new('Access Token expired', response.headers, code)
  else
    ERRORS[code].new(message, response.headers, code)
  end
end