Exception: Anthropic::Errors::APIStatusError

Inherits:
APIError
  • Object
show all
Defined in:
lib/anthropic/errors.rb,
sig/anthropic/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, #workspace_id

Constructor Details

#initialize(url:, status:, headers:, body:, request:, response:, message: nil, type: 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)
  • type (Anthropic::ErrorType::TaggedSymbol, nil) (defaults to: nil)


210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/anthropic/errors.rb', line 210

def initialize(url:, status:, headers:, body:, request:, response:, message: nil, type: nil)
  @type = type
  message ||= {url: url.to_s, status: status, body: body}
  super(
    url: url,
    status: status,
    headers: headers,
    body: body,
    request: request,
    response: response,
    message: message&.to_s
  )
end

Instance Attribute Details

#statusInteger

Returns:

  • (Integer)


# File 'lib/anthropic/errors.rb', line 196

#typeAnthropic::ErrorType::TaggedSymbol? (readonly)

Returns:

  • (Anthropic::ErrorType::TaggedSymbol, nil)


145
146
147
# File 'lib/anthropic/errors.rb', line 145

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.

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)


158
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
192
193
194
# File 'lib/anthropic/errors.rb', line 158

def self.for(url:, status:, headers:, body:, request:, response:, message: nil)
  error_type = body.dig(:error, :type) if body.is_a?(Hash)
  error_type = error_type.to_sym if error_type.is_a?(String)

  kwargs =
    {
      url: url,
      status: status,
      headers: headers,
      body: body,
      request: request,
      response: response,
      message: message,
      type: error_type
    }

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