Exception: VersSdk::APIError
- Inherits:
-
VersSDKError
- Object
- StandardError
- VersSDKError
- VersSdk::APIError
- Defined in:
- lib/vers_sdk/errors.rb
Overview
Error returned when the API responds with a non-success status code.
Direct Known Subclasses
APIConnectionError, AuthenticationError, BadRequestError, ConflictError, InternalServerError, NotFoundError, PermissionDeniedError, RateLimitError, UnprocessableEntityError
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(status: nil, body: nil, message: nil, headers: nil) ⇒ APIError
constructor
A new instance of APIError.
Constructor Details
#initialize(status: nil, body: nil, message: nil, headers: nil) ⇒ APIError
Returns a new instance of APIError.
14 15 16 17 18 19 |
# File 'lib/vers_sdk/errors.rb', line 14 def initialize(status: nil, body: nil, message: nil, headers: nil) @status = status @headers = headers @body = body super((status, body, )) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
12 13 14 |
# File 'lib/vers_sdk/errors.rb', line 12 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
12 13 14 |
# File 'lib/vers_sdk/errors.rb', line 12 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
12 13 14 |
# File 'lib/vers_sdk/errors.rb', line 12 def status @status end |
Class Method Details
.generate(status:, body: nil, message: nil, headers: nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/vers_sdk/errors.rb', line 21 def self.generate(status:, body: nil, message: nil, headers: nil) return APIConnectionError.new(message: ) if status.nil? || headers.nil? error_map = { 400 => BadRequestError, 401 => AuthenticationError, 403 => PermissionDeniedError, 404 => NotFoundError, 409 => ConflictError, 422 => UnprocessableEntityError, 429 => RateLimitError } error_cls = error_map[status] if error_cls return error_cls.new(status: status, body: body, message: , headers: headers) end if status >= 500 return InternalServerError.new(status: status, body: body, message: , headers: headers) end new(status: status, body: body, message: , headers: headers) end |