Skip to content

Commit

Permalink
error messages improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
anmol-yousaf committed Mar 30, 2021
1 parent 18716b5 commit c2073ad
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
8 changes: 7 additions & 1 deletion lib/active_campaign_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 5 additions & 2 deletions lib/active_campaign_wrapper/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion lib/active_campaign_wrapper/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module ActiveCampaignWrapper
VERSION = '0.1.1'
VERSION = '0.3.0'
end

0 comments on commit c2073ad

Please sign in to comment.