Exception: Fizzy::APIError

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

Overview

Raised for generic API errors.

Instance Attribute Summary

Attributes inherited from Error

#cause, #code, #hint, #http_status, #request_id, #retry_after, #retryable

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Error

#exit_code, exit_code_for, #retryable?

Constructor Details

#initialize(message, http_status: nil, hint: nil, retryable: false, cause: nil) ⇒ APIError

Returns a new instance of APIError.



192
193
194
195
196
197
198
199
200
201
# File 'lib/fizzy/errors.rb', line 192

def initialize(message, http_status: nil, hint: nil, retryable: false, cause: nil)
  super(
    code: ErrorCode::API,
    message: message,
    hint: hint,
    http_status: http_status,
    retryable: retryable,
    cause: cause
  )
end

Class Method Details

.from_status(status, message = nil) ⇒ APIError

Creates an APIError from an HTTP status code.

Parameters:

  • status (Integer)

    HTTP status code

  • message (String, nil) (defaults to: nil)

    optional error message

Returns:



207
208
209
210
211
# File 'lib/fizzy/errors.rb', line 207

def self.from_status(status, message = nil)
  message ||= "Request failed (HTTP #{status})"
  retryable = status >= 500 && status < 600
  new(message, http_status: status, retryable: retryable)
end