Exception: OpenAI::Errors::APIStatusError

Inherits:
APIError
  • Object
show all
Defined in:
lib/openai/errors.rb,
sig/openai/errors.rbs

Instance Attribute Summary collapse

Attributes inherited from APIError

#body, #headers, #url

Attributes inherited from Error

#cause

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from APIError

#request_id

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)


273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/openai/errors.rb', line 273

def initialize(url:, status:, headers:, body:, request:, response:, message: nil)
  message ||= case OpenAI::Internal::Util.dig(body, :message)
  in String | Symbol | Numeric | true | false => upstream_message
    upstream_message
  else
    safe_status_message(url: url, status: status, body: body)
  end

  @code = OpenAI::Internal::Type::Converter.coerce(String, (body, :code))
  @param = OpenAI::Internal::Type::Converter.coerce(String, (body, :param))
  @type = OpenAI::Internal::Type::Converter.coerce(String, (body, :type))
  super(
    url: url,
    status: status,
    headers: headers,
    body: body,
    request: request,
    response: response,
    message: message&.to_s
  )
end

Instance Attribute Details

#code ⇒ String?

Returns:

  • (String, nil)


# File 'lib/openai/errors.rb', line 252


#param ⇒ String?

Returns:

  • (String, nil)


# File 'lib/openai/errors.rb', line 256


#status ⇒ Integer

Returns:

  • (Integer)


# File 'lib/openai/errors.rb', line 248


#type ⇒ String?

Returns:

  • (String, nil)


# File 'lib/openai/errors.rb', line 260


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)


215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/openai/errors.rb', line 215

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

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