Exception: Coinbase::APIError
- Inherits:
-
StandardError
- Object
- StandardError
- Coinbase::APIError
- Defined in:
- lib/coinbase/errors.rb
Overview
A wrapper for API errors to provide more context.
Direct Known Subclasses
AlreadyExistsError, FaucetLimitReachedError, InternalError, InvalidAddressError, InvalidAddressIDError, InvalidAmountError, InvalidAssetIDError, InvalidDestinationError, InvalidLimitError, InvalidNetworkIDError, InvalidPageError, InvalidSignedPayloadError, InvalidTransferIDError, InvalidTransferStatusError, InvalidWalletError, InvalidWalletIDError, MalformedRequestError, NetworkFeatureUnsupportedError, NotFoundError, ResourceExhaustedError, UnauthorizedError, UnimplementedError, UnsupportedAssetError
Instance Attribute Summary collapse
-
#api_code ⇒ Object
readonly
Returns the value of attribute api_code.
-
#api_message ⇒ Object
readonly
Returns the value of attribute api_message.
-
#handled ⇒ Object
readonly
Returns the value of attribute handled.
-
#http_code ⇒ Object
readonly
Returns the value of attribute http_code.
Class Method Summary collapse
-
.from_error(err) ⇒ APIError
Creates a specific APIError based on the API error code.
Instance Method Summary collapse
-
#initialize(err, code: nil, message: nil, unhandled: false) ⇒ APIError
constructor
Initializes a new APIError object.
- #inspect ⇒ Object
-
#to_s ⇒ Object
Override to_s to display a friendly error message.
Constructor Details
#initialize(err, code: nil, message: nil, unhandled: false) ⇒ APIError
Initializes a new APIError object.
13 14 15 16 17 18 19 20 |
# File 'lib/coinbase/errors.rb', line 13 def initialize(err, code: nil, message: nil, unhandled: false) @http_code = err.code @api_code = code @api_message = @handled = code && && !unhandled super(err) end |
Instance Attribute Details
#api_code ⇒ Object (readonly)
Returns the value of attribute api_code.
9 10 11 |
# File 'lib/coinbase/errors.rb', line 9 def api_code @api_code end |
#api_message ⇒ Object (readonly)
Returns the value of attribute api_message.
9 10 11 |
# File 'lib/coinbase/errors.rb', line 9 def @api_message end |
#handled ⇒ Object (readonly)
Returns the value of attribute handled.
9 10 11 |
# File 'lib/coinbase/errors.rb', line 9 def handled @handled end |
#http_code ⇒ Object (readonly)
Returns the value of attribute http_code.
9 10 11 |
# File 'lib/coinbase/errors.rb', line 9 def http_code @http_code end |
Class Method Details
.from_error(err) ⇒ APIError
Creates a specific APIError based on the API error code.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/coinbase/errors.rb', line 25 def self.from_error(err) raise ArgumentError, 'Argument must be a Coinbase::Client::APIError' unless err.is_a? Coinbase::Client::ApiError return APIError.new(err) unless err.response_body begin body = JSON.parse(err.response_body) rescue JSON::ParserError return APIError.new(err) end = body['message'] code = body['code'] if ERROR_CODE_TO_ERROR_CLASS.key?(code) ERROR_CODE_TO_ERROR_CLASS[code].new(err, code: code, message: ) else APIError.new(err, code: code, message: , unhandled: true) end end |
Instance Method Details
#inspect ⇒ Object
54 55 56 |
# File 'lib/coinbase/errors.rb', line 54 def inspect to_s end |
#to_s ⇒ Object
Override to_s to display a friendly error message
46 47 48 49 50 51 52 |
# File 'lib/coinbase/errors.rb', line 46 def to_s # For handled errors, display just the API message as that provides sufficient context. return if handled # For unhandled errors, display the full error message super end |