Exception: OpenAI::Errors::APIStatusError
- Defined in:
- lib/openai/errors.rb
Direct Known Subclasses
AuthenticationError, BadRequestError, ConflictError, InternalServerError, NotFoundError, PermissionDeniedError, RateLimitError, UnprocessableEntityError
Instance Attribute Summary collapse
Attributes inherited from APIError
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.
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.
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/openai/errors.rb', line 218 def initialize(url:, status:, headers:, body:, request:, response:, message: nil) ||= 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, headers: headers, body: body, request: request, response: response, message: &.to_s ) end |
Instance Attribute Details
#code ⇒ String?
2 3 4 |
# File 'lib/openai/errors.rb', line 2 def code @code end |
#param ⇒ String?
2 3 4 |
# File 'lib/openai/errors.rb', line 2 def param @param end |
#status ⇒ Integer
2 3 4 |
# File 'lib/openai/errors.rb', line 2 def status @status end |
#type ⇒ String?
2 3 4 |
# File 'lib/openai/errors.rb', line 2 def type @type 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.
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 191 |
# File 'lib/openai/errors.rb', line 159 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 |