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, 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.
-
#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) ⇒ APIError
constructor
Initializes a new APIError object.
-
#inspect ⇒ String
Same as to_s.
-
#to_s ⇒ String
Returns a String representation of the APIError.
Constructor Details
#initialize(err) ⇒ APIError
Initializes a new APIError object.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/coinbase/errors.rb', line 13 def initialize(err) super @http_code = err.code return unless err.response_body body = JSON.parse(err.response_body) @api_code = body['code'] @api_message = body['message'] 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 |
#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. rubocop:disable Metrics/MethodLength
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/coinbase/errors.rb', line 28 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 body = JSON.parse(err.response_body) case body['code'] when 'unimplemented' UnimplementedError.new(err) when 'unauthorized' UnauthorizedError.new(err) when 'internal' InternalError.new(err) when 'not_found' NotFoundError.new(err) when 'invalid_wallet_id' InvalidWalletIDError.new(err) when 'invalid_address_id' InvalidAddressIDError.new(err) when 'invalid_wallet' InvalidWalletError.new(err) when 'invalid_address' InvalidAddressError.new(err) when 'invalid_amount' InvalidAmountError.new(err) when 'invalid_transfer_id' InvalidTransferIDError.new(err) when 'invalid_page_token' InvalidPageError.new(err) when 'invalid_page_limit' InvalidLimitError.new(err) when 'already_exists' AlreadyExistsError.new(err) when 'malformed_request' MalformedRequestError.new(err) when 'unsupported_asset' UnsupportedAssetError.new(err) when 'invalid_asset_id' InvalidAssetIDError.new(err) when 'invalid_destination' InvalidDestinationError.new(err) when 'invalid_network_id' InvalidNetworkIDError.new(err) when 'resource_exhausted' ResourceExhaustedError.new(err) when 'faucet_limit_reached' FaucetLimitReachedError.new(err) when 'invalid_signed_payload' InvalidSignedPayloadError.new(err) when 'invalid_transfer_status' InvalidTransferStatusError.new(err) else APIError.new(err) end end |
Instance Method Details
#inspect ⇒ String
Same as to_s.
93 94 95 |
# File 'lib/coinbase/errors.rb', line 93 def inspect to_s end |
#to_s ⇒ String
Returns a String representation of the APIError.
87 88 89 |
# File 'lib/coinbase/errors.rb', line 87 def to_s "APIError{http_code: #{@http_code}, api_code: #{@api_code}, api_message: #{@api_message}}" end |