Skip to content

Commit

Permalink
Merge pull request #35 from asonas/feature/raise_error
Browse files Browse the repository at this point in the history
raise error when status 4xx and 5xx
  • Loading branch information
sue445 committed Jan 11, 2018
2 parents 5c808b3 + ccad148 commit 260726c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/chatwork/base_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def handle_response(response)
raise ChatWork::APIConnectionError.new("Response JSON is broken. #{e.message}: #{response.body}", e)
end
else
ChatWork::ChatWorkError.from_response(response.status, response.body, response.headers)
raise ChatWork::ChatWorkError.from_response(response.status, response.body, response.headers)
end
end

Expand Down
8 changes: 8 additions & 0 deletions spec/lib/chatwork/me_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,13 @@
end

it_behaves_like :a_chatwork_api, :get, "/me"

context "when unauthorized" do
before do
stub_chatwork_request(:get, "/me", "/me", 401)
end

it { expect { subject }.to raise_error(ChatWork::APIError, "Invalid API token") }
end
end
end

0 comments on commit 260726c

Please sign in to comment.