Exception: Anthropic::Errors::APIStatusError
- Defined in:
- lib/anthropic/errors.rb,
sig/anthropic/errors.rbs
Direct Known Subclasses
AuthenticationError, BadRequestError, ClientClosedRequestError, ConflictError, ContentTooLargeError, InternalServerError, NotFoundError, PaymentRequiredError, PermissionDeniedError, PreconditionFailedError, RateLimitError, RequestHeaderFieldsTooLargeError, RequestTimeoutError, UnprocessableEntityError
Instance Attribute Summary collapse
Attributes inherited from APIError
Attributes inherited from Error
Class Method Summary collapse
Instance Method Summary collapse
- #`type` ⇒ Anthropic::Models::error_type?
-
#api_message ⇒ String?
A human-readable explanation of the error.
-
#details ⇒ Anthropic::Models::ErrorDetails?
Machine-readable detail about the cause of the error.
-
#error_code ⇒ Symbol?
A stable code that names the cause.
-
#initialize(url:, status:, headers:, body:, request:, response:, message: nil) ⇒ APIStatusError
constructor
private
A new instance of APIStatusError.
-
#type ⇒ Symbol, ...
The broad category of the error.
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.
229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/anthropic/errors.rb', line 229 def initialize(url:, status:, headers:, body:, request:, response:, message: nil) ||= {url: url.to_s, status: status, body: body} super( url: url, status: status, headers: headers, body: body, request: request, response: response, message: &.to_s ) end |
Instance Attribute Details
#status ⇒ Integer
|
|
# File 'lib/anthropic/errors.rb', line 216
|
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.
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/anthropic/errors.rb', line 197 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: } error_code = Anthropic::Internal::Util.dig(body, [:error, :details, :error_code]) error_class = Anthropic::Errors::ERROR_CLASSES[[status, error_code]] error_class ||= Anthropic::Errors::ERROR_CLASSES[[status, nil]] error_class ||= status >= 500 ? Anthropic::Errors::InternalServerError : Anthropic::Errors::APIStatusError error_class.new(**kwargs) end |
Instance Method Details
#`type` ⇒ Anthropic::Models::error_type?
73 |
# File 'sig/anthropic/errors.rbs', line 73
def `type`: -> Anthropic::Models::error_type?
|
#api_message ⇒ String?
A human-readable explanation of the error. Its wording can change, so don't match on it.
error.message from the response body, if present.
150 |
# File 'lib/anthropic/errors.rb', line 150 def = Anthropic::Internal::Util.dig(body, [:error, :message]) |
#details ⇒ Anthropic::Models::ErrorDetails?
Machine-readable detail about the cause of the error. error_code names the
cause; branch on it rather than on message. Absent when the error has no code.
Treat an unrecognized error_code as the bare type.
error.details from the response body, if present.
179 180 181 182 183 184 |
# File 'lib/anthropic/errors.rb', line 179 def details Anthropic::Internal::Type::Converter.coerce( Anthropic::ErrorDetails, Anthropic::Internal::Util.dig(body, [:error, :details]) ) end |
#error_code ⇒ Symbol?
A stable code that names the cause.
error.details.error_code from the response body, if present and a string.
167 168 169 170 |
# File 'lib/anthropic/errors.rb', line 167 def error_code code = Anthropic::Internal::Util.dig(body, [:error, :details, :error_code]) code.to_sym if code.is_a?(String) end |
#type ⇒ Symbol, ...
The broad category of the error.
error.type from the response body, if present.
157 158 159 160 |
# File 'lib/anthropic/errors.rb', line 157 def type value = Anthropic::Internal::Util.dig(body, [:error, :type]) value.is_a?(String) ? value.to_sym : value end |