Class: IContact::ErrorHandler
- Inherits:
-
Object
- Object
- IContact::ErrorHandler
- Defined in:
- lib/icontact/errors.rb
Constant Summary collapse
- MAPPED_ERRORS =
{ 400 => IContact::BadRequest, 401 => IContact::NotAuthorized, 402 => IContact::PaymentRequest, 403 => IContact::Forbidden, 405 => IContact::MethodNotAllowed, 406 => IContact::NotAcceptable, 415 => IContact::UnsupportedMediaType, 500 => IContact::InternalServer, 501 => IContact::NotImplemented, 503 => IContact::ServiceUnavailable, 507 => IContact::InsufficientSpace }
Instance Method Summary collapse
-
#initialize(response) ⇒ ErrorHandler
constructor
A new instance of ErrorHandler.
Constructor Details
#initialize(response) ⇒ ErrorHandler
Returns a new instance of ErrorHandler.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/icontact/errors.rb', line 43 def initialize(response) klass = MAPPED_ERRORS[response.status.to_i] parsed = Oj.load(response.body || '') = parsed.nil? ? '' : parsed['errors'] if klass raise klass.new() else raise IContactError.new("#{response.status}: #{}") end end |