Skip to content
Merged
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
6 changes: 5 additions & 1 deletion lib/mailjet/exception/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ def initialize(message = nil, response = nil)
end

api_message = begin
Yajl::Parser.parse(response.response_body)['ErrorMessage']
if response.response_body.present?
Yajl::Parser.parse(response.response_body)['ErrorMessage']
else
'Unauthorized'
end
rescue Yajl::ParseError
response.response_body
rescue NoMethodError
Expand Down
2 changes: 1 addition & 1 deletion spec/resources/resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RSpec.describe Mailjet::Resource, :vcr do
context '/invalid_credentials' do
it 'should raise api connection error' do
expect{ Mailjet::Apikey.first }.to raise_error(Mailjet::Unauthorized, /the server responded with status 401 - Invalid Domain or API key/)
expect{ Mailjet::Apikey.first }.to raise_error(Mailjet::Unauthorized, /Invalid Domain or API key: Unauthorized/)
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/resources/send_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
}]
}

expect{ described_class.create(message, version: 'v3.1') }.to raise_error(Mailjet::Unauthorized, /the server responded with status 401 - Invalid Domain or API key/)
expect{ described_class.create(message, version: 'v3.1') }.to raise_error(Mailjet::Unauthorized, /Visit API keys management section to check your keys/)
end
end
end