Skip to content

Commit cf44f68

Browse files
authored
DE-1570: Respond with error message for 400 Bad Request (#360)
* DE-1570: Respond with error message for 400 Bad Request Signed-off-by: Alex Lebedev <[email protected]> * DE-1570: fix specs Signed-off-by: Alex Lebedev <[email protected]> --------- Signed-off-by: Alex Lebedev <[email protected]>
1 parent 3fd2c3e commit cf44f68

File tree

6 files changed

+21
-9
lines changed

6 files changed

+21
-9
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [1.3.8] - 2025-07-23
6+
7+
- Respond with error message for 400 Bad Request
8+
9+
## [1.3.7] - 2025-06-29
10+
11+
- Use proxy_url passed to constructor (https://github.com/mailgun/mailgun-ruby/pull/342)
12+
- Refactor to use UserNotifier instead of UserMailer for consistency (https://github.com/mailgun/mailgun-ruby/pull/323)
13+
- Add option to specify api key and host when initializing Address api (https://github.com/mailgun/mailgun-ruby/pull/328)
14+
- Remove base64 dependency (https://github.com/mailgun/mailgun-ruby/pull/313)
15+
- DE-1547: Support for the logs API (https://github.com/mailgun/mailgun-ruby/pull/356)
16+
517
## [1.3.6] - 2025-05-30
618

719
### Fixed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ gem install mailgun-ruby
1919
Gemfile:
2020

2121
```ruby
22-
gem 'mailgun-ruby', '~>1.3.7'
22+
gem 'mailgun-ruby', '~>1.3.8'
2323
```
2424

2525
Usage

lib/mailgun/exceptions/exceptions.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ def initialize(message = nil, response = nil)
4646
@status = if response.nil?
4747
NOCODE
4848
else
49-
response.status
49+
response[:status]
5050
end
5151

5252
begin
53-
json = JSON.parse(response.body)
53+
json = JSON.parse(response[:body])
5454
api_message = json['message'] || json['Error'] || json['error']
5555
rescue JSON::ParserError
5656
api_message = response.response_body

lib/mailgun/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# It's the version. Yeay!
22
module Mailgun
3-
VERSION = '1.3.7'
3+
VERSION = '1.3.8'
44
end

spec/integration/mailgun_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
:text => 'INTEGRATION TESTING'
2828
})
2929
rescue Mailgun::CommunicationError => err
30-
expect(err.message).to eq('the server responded with status 404')
30+
expect(err.message).to eq('the server responded with status 404: Domain not found: not-our-doma.in')
3131
else
3232
fail
3333
end
@@ -75,7 +75,7 @@
7575
:text => 'INTEGRATION TESTING'
7676
})
7777
rescue Mailgun::BadRequest => err
78-
expect(err.message).to eq('the server responded with status 400')
78+
expect(err.message).to eq('the server responded with status 400: to parameter is not a valid address. please check documentation')
7979
else
8080
fail
8181
end

spec/unit/exceptions/exceptions_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
context "when the Response body doesn't have a `message` property" do
66
it "doesn't raise an error" do
77
expect do
8-
described_class.new('Boom!', Mailgun::Response.from_hash({ status: 401, body: '{}' }))
8+
described_class.new('Boom!', { status: 401, body: '{}' })
99
end.not_to raise_error
1010
end
1111

1212
context "when the Response body has an `Error` property" do
1313
it "uses the `Error` property as the API message" do
14-
subject = described_class.new('Boom!', Mailgun::Response.from_hash({ status: 401, body: '{"Error":"unauthorized"}' }))
14+
subject = described_class.new('Boom!', { status: 401, body: '{"Error":"unauthorized"}' })
1515

1616
expect(subject.message).to eq("Boom!: unauthorized")
1717
end
1818
end
1919

2020
context "when the Response body has an `error` property" do
2121
it "uses the `Error` property as the API message" do
22-
subject = described_class.new('Boom!', Mailgun::Response.from_hash({ status: 401, body: '{"error":"not found"}' }))
22+
subject = described_class.new('Boom!', { status: 401, body: '{"error":"not found"}' })
2323

2424
expect(subject.message).to eq("Boom!: not found")
2525
end

0 commit comments

Comments
 (0)