diff --git a/lib/taxjar/error.rb b/lib/taxjar/error.rb index 7bb3afd..cad5976 100644 --- a/lib/taxjar/error.rb +++ b/lib/taxjar/error.rb @@ -67,7 +67,13 @@ def from_response(body) def from_response_code(code) message = HTTP::Response::Status::REASONS[code] || "Unknown Error" - new(message, code) + klass = case code + when 400...500 then ClientError + when 500...600 then ServerError + else + self + end + klass.new(message, code) end def for_json_parse_error(code)