Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/action_network_rest/response/raise_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def on_complete(response)
if error_message == 'You must specify a valid person id'
raise MustSpecifyValidPersonId, error_message(response)
end
elsif status_code == 403
raise AuthorizationError, error_message(response)
elsif status_code == 404
raise NotFoundError, error_message(response)
elsif status_code == 429
Expand All @@ -31,6 +33,8 @@ def error_message(response)
end
end

class AuthorizationError < StandardError; end

class MissingActionNetworkId < StandardError; end

class MustSpecifyValidPersonId < StandardError; end
Expand Down
7 changes: 7 additions & 0 deletions spec/response/raise_error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
.to(raise_error(ActionNetworkRest::Response::MustSpecifyValidPersonId, /You must specify a valid person id/))
end


it 'should raise AuthorizationError if status is 403' do
response = { status: '403', body: { error: 'API Key invalid or not present' }.to_json }

expect { subject.on_complete(response) }.to raise_error(ActionNetworkRest::Response::AuthorizationError, /API Key invalid/)
end

it 'should raise NotFoundError if status is 404' do
response = { status: '404', body: { error: 'Not found' }.to_json }

Expand Down