From 7e90dd5b57aef63745cafeeb7a769bc11a1eb2ca Mon Sep 17 00:00:00 2001 From: Alex Lebedev <6421109+alex-leb@users.noreply.github.com> Date: Tue, 26 Aug 2025 21:48:21 +0300 Subject: [PATCH] DE-1590: Fix specs Signed-off-by: Alex Lebedev <6421109+alex-leb@users.noreply.github.com> --- lib/mailjet/exception/errors.rb | 6 +++++- spec/resources/resource_spec.rb | 2 +- spec/resources/send_spec.rb | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/mailjet/exception/errors.rb b/lib/mailjet/exception/errors.rb index ef77fb1..fba6a6a 100644 --- a/lib/mailjet/exception/errors.rb +++ b/lib/mailjet/exception/errors.rb @@ -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 diff --git a/spec/resources/resource_spec.rb b/spec/resources/resource_spec.rb index b10e60e..5a7d779 100644 --- a/spec/resources/resource_spec.rb +++ b/spec/resources/resource_spec.rb @@ -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 diff --git a/spec/resources/send_spec.rb b/spec/resources/send_spec.rb index e8748a1..53a2926 100644 --- a/spec/resources/send_spec.rb +++ b/spec/resources/send_spec.rb @@ -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