Exception: OpenAI::Errors::APIStatusError

Inherits:
APIError
  • Object
show all
Defined in:
lib/openai/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)


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

def initialize(url:, status:, body:, request:, response:, message: nil)
  message ||= OpenAI::Internal::Util.dig(body, :message) { {url: url.to_s, status: status, body: body} }
  @code = OpenAI::Internal::Type::Converter.coerce(String, OpenAI::Internal::Util.dig(body, :code))
  @param = OpenAI::Internal::Type::Converter.coerce(String, OpenAI::Internal::Util.dig(body, :param))
  @type = OpenAI::Internal::Type::Converter.coerce(String, OpenAI::Internal::Util.dig(body, :type))
  super(
    url: url,
    status: status,
    body: body,
    request: request,
    response: response,
    message: message&.to_s
  )
end

Instance Attribute Details

#codeString?

Returns:

  • (String, nil)


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

def code
  @code
end

#paramString?

Returns:

  • (String, nil)


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

def param
  @param
end

#statusInteger

Returns:

  • (Integer)


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

def status
  @status
end

#typeString?

Returns:

  • (String, nil)


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

def type
  @type
end

Class Method Details

.for(url:, status:, 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)
  • body (Object, nil)
  • request (nil)
  • response (nil)
  • message (String, nil) (defaults to: nil)

Returns:

  • (self)


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
# File 'lib/openai/errors.rb', line 149

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
    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