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
6 changes: 1 addition & 5 deletions lib/mailgun/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,7 @@ def self.submit(method, url, parameters={})
:code => error_code || nil,
:message => error_message || nil
)
if error.handle.kind_of? Mailgun::ErrorBase
raise error.handle
else
raise error
end
raise error.handle if error.handle
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/mailgun/mailgun_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def handle

class NotFound < ErrorBase
def handle
return nil
nil
end
end

Expand Down
31 changes: 31 additions & 0 deletions spec/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,37 @@

Mailgun.submit :test_method, '/', :arg1=>"val1"
end

context "when the client raises a 400 http error" do
it "should re-raise a bad request mailgun error" do
client_error = Mailgun::ClientError.new
client_error.http_code = 400
client_error.http_body = { "message" => "Expression is missing" }.to_json
expect(Mailgun::Client).to receive(:new)
.with('/')
.and_return(client_double)
expect(client_double).to receive(:test_method)
.with({:arg1=>"val1"})
.and_raise(client_error)

expect { Mailgun.submit :test_method, '/', :arg1=>"val1" }.to raise_exception Mailgun::BadRequest
end
end
context "when the client raises a 404 http error" do
it "should return nil instead of raising an exception" do
client_error = Mailgun::ClientError.new
client_error.http_code = 404
client_error.http_body = { "message" => "Not Found" }.to_json
expect(Mailgun::Client).to receive(:new)
.with('/')
.and_return(client_double)
expect(client_double).to receive(:test_method)
.with({:arg1=>"val1"})
.and_raise(client_error)

expect(Mailgun.submit :test_method, '/', :arg1=>"val1").to be_nil
end
end
end
end

Expand Down