Exception: Increase::Errors::APIStatusError

Inherits:
APIError
  • Object
show all
Defined in:
lib/increase/errors.rb

Instance Attribute Summary collapse

Attributes inherited from APIError

#body, #headers, #url

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, status:, headers:, 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)
  • headers (Hash{String=>String}, nil)
  • body (Object, nil)
  • request (nil)
  • response (nil)
  • message (String, nil) (defaults to: nil)


205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/increase/errors.rb', line 205

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

Instance Attribute Details

#statusInteger

Returns:

  • (Integer)


2
3
4
# File 'lib/increase/errors.rb', line 2

def status
  @status
end

Class Method Details

.for(url:, status:, headers:, body:, request:, response:, message: nil) ⇒ self

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)
  • headers (Hash{String=>String}, nil)
  • body (Object, nil)
  • request (nil)
  • response (nil)
  • message (String, nil) (defaults to: nil)

Returns:

  • (self)


135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/increase/errors.rb', line 135

def self.for(url:, status:, headers:, body:, request:, response:, message: nil)
  key = Increase::Internal::Util.dig(body, :type)
  kwargs =
    {
      url: url,
      status: status,
      headers: headers,
      body: body,
      request: request,
      response: response,
      message: message
    }

  case [status, key]
  in [400, Increase::Errors::InvalidParametersError::TYPE]
    Increase::Errors::InvalidParametersError.new(**kwargs)
  in [400, Increase::Errors::MalformedRequestError::TYPE]
    Increase::Errors::MalformedRequestError.new(**kwargs)
  in [401, Increase::Errors::InvalidAPIKeyError::TYPE]
    Increase::Errors::InvalidAPIKeyError.new(**kwargs)
  in [403, Increase::Errors::EnvironmentMismatchError::TYPE]
    Increase::Errors::EnvironmentMismatchError.new(**kwargs)
  in [403, Increase::Errors::InsufficientPermissionsError::TYPE]
    Increase::Errors::InsufficientPermissionsError.new(**kwargs)
  in [403, Increase::Errors::PrivateFeatureError::TYPE]
    Increase::Errors::PrivateFeatureError.new(**kwargs)
  in [404, Increase::Errors::APIMethodNotFoundError::TYPE]
    Increase::Errors::APIMethodNotFoundError.new(**kwargs)
  in [404, Increase::Errors::ObjectNotFoundError::TYPE]
    Increase::Errors::ObjectNotFoundError.new(**kwargs)
  in [409, Increase::Errors::IdempotencyKeyAlreadyUsedError::TYPE]
    Increase::Errors::IdempotencyKeyAlreadyUsedError.new(**kwargs)
  in [409, Increase::Errors::InvalidOperationError::TYPE]
    Increase::Errors::InvalidOperationError.new(**kwargs)
  in [429, Increase::Errors::RateLimitedError::TYPE]
    Increase::Errors::RateLimitedError.new(**kwargs)
  in [(500..), Increase::Errors::InternalServerError::TYPE]
    Increase::Errors::InternalServerError.new(**kwargs)
  in [400, _]
    Increase::Errors::BadRequestError.new(**kwargs)
  in [401, _]
    Increase::Errors::AuthenticationError.new(**kwargs)
  in [403, _]
    Increase::Errors::PermissionDeniedError.new(**kwargs)
  in [404, _]
    Increase::Errors::NotFoundError.new(**kwargs)
  in [409, _]
    Increase::Errors::ConflictError.new(**kwargs)
  in [422, _]
    Increase::Errors::UnprocessableEntityError.new(**kwargs)
  in [429, _]
    Increase::Errors::RateLimitError.new(**kwargs)
  else
    Increase::Errors::APIStatusError.new(**kwargs)
  end
end