Exception: OpenAI::Errors::APIStatusError
- Defined in:
- lib/openai/errors.rb,
sig/openai/errors.rbs
Direct Known Subclasses
AuthenticationError, BadRequestError, ConflictError, InternalServerError, NotFoundError, OAuthError, PermissionDeniedError, RateLimitError, UnprocessableEntityError
Instance Attribute Summary collapse
Attributes inherited from APIError
Attributes inherited from Error
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(url:, status:, headers:, body:, request:, response:, message: nil) ⇒ APIStatusError
constructor
private
A new instance of APIStatusError.
Methods inherited from APIError
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.
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/openai/errors.rb', line 259 def initialize(url:, status:, headers:, body:, request:, response:, message: nil) ||= case OpenAI::Internal::Util.dig(body, :message) in String | Symbol | Numeric | true | false => else (url: url, status: status, body: body) end @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, headers: headers, body: body, request: request, response: response, message: &.to_s ) end |
Instance Attribute Details
#code ⇒ String?
|
|
# File 'lib/openai/errors.rb', line 238
|
#param ⇒ String?
|
|
# File 'lib/openai/errors.rb', line 242
|
#status ⇒ Integer
|
|
# File 'lib/openai/errors.rb', line 234
|
#type ⇒ String?
|
|
# File 'lib/openai/errors.rb', line 246
|
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.
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/openai/errors.rb', line 201 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: } 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 |