Exception: FinchAPI::APIStatusError

Inherits:
APIError show all
Defined in:
lib/finch-api/errors.rb

Instance Attribute Summary collapse

Attributes inherited from APIError

#body, #url

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, status:, body:, request:, response:, message: nil) ⇒ APIStatusError

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 new instance of APIStatusError.

Parameters:

  • url (URI::Generic)
  • status (Integer)
  • body (Object, nil)
  • request (nil)
  • response (nil)
  • message (String, nil) (defaults to: nil)


139
140
141
142
143
144
145
146
147
148
149
# File 'lib/finch-api/errors.rb', line 139

def initialize(url:, status:, body:, request:, response:, message: nil)
  message ||= {url: url.to_s, status: status, body: body}
  super(
    url: url,
    status: status,
    body: body,
    request: request,
    response: response,
    message: message&.to_s
  )
end

Instance Attribute Details

#statusInteger

Returns:

  • (Integer)


2
3
4
# File 'lib/finch-api/errors.rb', line 2

def status
  @status
end

Class Method Details

.for(url:, status:, body:, request:, response:, message: nil) ⇒ FinchAPI::APIStatusError

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.

Parameters:

  • url (URI::Generic)
  • status (Integer)
  • body (Object, nil)
  • request (nil)
  • response (nil)
  • message (String, nil) (defaults to: nil)

Returns:



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/finch-api/errors.rb', line 102

def self.for(url:, status:, body:, request:, response:, message: nil)
  kwargs = {url: url, status: status, body: body, request: request, response: response, message: message}

  case status
  in 400
    FinchAPI::BadRequestError.new(**kwargs)
  in 401
    FinchAPI::AuthenticationError.new(**kwargs)
  in 403
    FinchAPI::PermissionDeniedError.new(**kwargs)
  in 404
    FinchAPI::NotFoundError.new(**kwargs)
  in 409
    FinchAPI::ConflictError.new(**kwargs)
  in 422
    FinchAPI::UnprocessableEntityError.new(**kwargs)
  in 429
    FinchAPI::RateLimitError.new(**kwargs)
  in (500..)
    FinchAPI::InternalServerError.new(**kwargs)
  else
    FinchAPI::APIStatusError.new(**kwargs)
  end
end