Exception: Taxjar::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/taxjar/error.rb

Constant Summary collapse

ClientError =
Class.new(self)
ServerError =
Class.new(self)
BadRequest =

Raised when Taxjar endpoint returns the HTTP status code 400

Class.new(ClientError)
Unauthorized =

Raised when Taxjar endpoint returns the HTTP status code 401

Class.new(ClientError)
Forbidden =

Raised when Taxjar endpoint returns the HTTP status code 403

Class.new(ClientError)
NotFound =

Raised when Taxjar endpoint returns the HTTP status code 404

Class.new(ClientError)
MethodNotAllowed =

Raised when Taxjar endpoint returns the HTTP status code 405

Class.new(ClientError)
NotAcceptable =

Raised when Taxjar endpoint returns the HTTP status code 406

Class.new(ClientError)
Gone =

Raised when Taxjar endpoint returns the HTTP status code 410

Class.new(ClientError)
UnprocessableEntity =

Raised when Taxjar endpoint returns the HTTP status code 422

Class.new(ClientError)
TooManyRequests =

Raised when Taxjar endpoint returns the HTTP status code 429

Class.new(ClientError)
InternalServerError =

Raised when Taxjar endpoint returns the HTTP status code 500

Class.new(ServerError)
ServiceUnavailable =

Raised when Taxjar endpoint returns the HTTP status code 503

Class.new(ServerError)
GatewayTimeout =

Raised when Taxjar endpoint returns the HTTP status code 504

Class.new(ServerError)
ERRORS =
{
  400 => Taxjar::Error::BadRequest,
  401 => Taxjar::Error::Unauthorized,
  403 => Taxjar::Error::Forbidden,
  404 => Taxjar::Error::NotFound,
  405 => Taxjar::Error::MethodNotAllowed,
  406 => Taxjar::Error::NotAcceptable,
  410 => Taxjar::Error::Gone,
  422 => Taxjar::Error::UnprocessableEntity,
  429 => Taxjar::Error::TooManyRequests,
  500 => Taxjar::Error::InternalServerError,
  503 => Taxjar::Error::ServiceUnavailable,
  504 => Taxjar::Error::GatewayTimeout
}
ConfigurationError =
Class.new(::ArgumentError)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = '', code = nil) ⇒ Error

Returns a new instance of Error.



79
80
81
82
# File 'lib/taxjar/error.rb', line 79

def initialize(message = '', code = nil)
  super(message)
  @code = code
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



3
4
5
# File 'lib/taxjar/error.rb', line 3

def code
  @code
end

Class Method Details

.for_json_parse_error(code) ⇒ Object



73
74
75
# File 'lib/taxjar/error.rb', line 73

def for_json_parse_error(code)
  ServerError.new("Couldn't parse response as JSON.", code)
end

.from_response(body) ⇒ Object



62
63
64
65
66
# File 'lib/taxjar/error.rb', line 62

def from_response(body)
  code = body[:status]
  message = body[:detail]
  new(message, code)
end

.from_response_code(code) ⇒ Object



68
69
70
71
# File 'lib/taxjar/error.rb', line 68

def from_response_code(code)
  message = HTTP::Response::Status::REASONS[code] || "Unknown Error"
  new(message, code)
end