Skip to content

Commit

Permalink
Properly catches 400 Bad Request exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
inf0rmer committed Apr 21, 2015
1 parent 96cc1b1 commit ea887d7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/blanket/wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def request(method, id=nil, options={})
body: options[:body]
}.reject { |_, value| value.nil? || value.empty? })

if response.code <= 400
if response.code < 400
body = (response.respond_to? :body) ? response.body : nil
(body.is_a? Array) ? body.map(Response.new) : Response.new(body)
else
Expand Down
10 changes: 10 additions & 0 deletions spec/blanket/wrapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@
Blanket::wrap("http://api.example.org")
end

describe "400" do
before :each do
stub_request(:get, "http://api.example.org/users").to_return(:status => 400, :body => "You've been met with a terrible fate, haven't you?")
end

it "raises a Blanket::BadRequestError exception" do
expect { api.users.get }.to raise_exception(Blanket::BadRequest)
end
end

describe "500" do
before :each do
stub_request(:get, "http://api.example.org/users").to_return(:status => 500, :body => "You've been met with a terrible fate, haven't you?")
Expand Down

0 comments on commit ea887d7

Please sign in to comment.