diff --git a/lib/active_campaign_wrapper.rb b/lib/active_campaign_wrapper.rb index 1816c55..760cc6c 100644 --- a/lib/active_campaign_wrapper.rb +++ b/lib/active_campaign_wrapper.rb @@ -17,5 +17,11 @@ def config class Error < StandardError; end - class AuthorizationError < StandardError; end + class Forbidden < StandardError; end + + class UnprocessableEntity < StandardError; end + + class NotFound < StandardError; end + + class TooManyRequests < StandardError; end end diff --git a/lib/active_campaign_wrapper/helpers.rb b/lib/active_campaign_wrapper/helpers.rb index 6fcc173..9e2537c 100644 --- a/lib/active_campaign_wrapper/helpers.rb +++ b/lib/active_campaign_wrapper/helpers.rb @@ -7,8 +7,11 @@ module Helpers module_function def normalize_response(response) - raise ActiveCampaignWrapper::AuthorizationError, response.message if response.unauthorized? - raise ActiveCampaignWrapper::Error, response.message unless response.success? + raise ActiveCampaignWrapper::Forbidden, response['message'] if response.forbidden? + raise ActiveCampaignWrapper::NotFound, response['message'] if response.not_found? + raise ActiveCampaignWrapper::UnprocessableEntity, response['errors']&.join(', ') || response['error'] if response.unprocessable_entity? + raise ActiveCampaignWrapper::TooManyRequests, response['message'] if response.too_many_requests? + raise ActiveCampaignWrapper::Error, response['message'] unless response.success? if response&.body.present? transform_keys(response, [:underscore]) diff --git a/lib/active_campaign_wrapper/version.rb b/lib/active_campaign_wrapper/version.rb index ccfe722..533e988 100644 --- a/lib/active_campaign_wrapper/version.rb +++ b/lib/active_campaign_wrapper/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module ActiveCampaignWrapper - VERSION = '0.1.1' + VERSION = '0.3.0' end