Method: CoinbaseCommerceClient::Errors.specific_api_error

Defined in:
lib/coinbase_commerce_client/api_errors.rb

.specific_api_error(resp, error_data) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/coinbase_commerce_client/api_errors.rb', line 100

def self.specific_api_error(resp, error_data)
  opts = {
    http_body: resp.http_body,
    http_headers: resp.http_headers,
    http_status: resp.http_status,
    json_body: resp.data
  }
  case resp.http_status
  when 400
    # in case of known error code
    case error_data[:type]
    when 'param_required'
      ParamRequiredError.new(error_data[:message], opts)
    when 'validation_error'
      ValidationError.new(error_data[:message], opts)
    when 'invalid_request'
      InvalidRequestError.new(error_data[:message], opts)
    else
      InvalidRequestError.new(error_data[:message], opts)
    end
  when 401
    AuthenticationError.new(error_data[:message], opts)
  when 404
    ResourceNotFoundError.new(error_data[:message], opts)
  when 429
    RateLimitExceededError.new(error_data[:message], opts)
  when 500
    InternalServerError.new(error_data[:message], opts)
  when 503
    ServiceUnavailableError.new(error_data[:message], opts)
  else
    APIError.new(error_data[:message], opts)
  end
end