Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose error details on 500 #14

Merged
merged 1 commit into from
Mar 29, 2018
Merged
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
3 changes: 2 additions & 1 deletion lib/help_scout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ def request(method, path, options)
when HTTP_NOT_FOUND
raise NotFoundError
when HTTP_INTERNAL_SERVER_ERROR
raise InternalServerError
error_message = JSON.parse(last_response.body)["error"]
raise InternalServerError, error_message
when HTTP_TOO_MANY_REQUESTS
retry_after = last_response.headers["Retry-After"]
error_message = "Rate limit of 200 RPM or 12 POST/PUT/DELETE requests per 5 seconds reached. Next request possible in #{retry_after} seconds."
Expand Down
17 changes: 14 additions & 3 deletions spec/helpscout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,22 @@
end

context 'with a 500 status code' do
it 'returns InternalServerError' do
it 'returns InternalServerError with body' do
expected_error_message = "Did not find any valid email for customer 1111"

url = 'https://api.helpscout.net/v1/conversations/1337.json'
stub_request(:get, url).to_return(status: 500)
stub_request(:post, url).
to_return(
status: 500,
body: {
"code": 500,
"error": expected_error_message,
}.to_json,
)

expect { client.get_conversation(1337) }.to raise_error(HelpScout::InternalServerError)
expect {
client.create_thread(conversation_id: 1337, thread: {})
}.to raise_error(HelpScout::InternalServerError, expected_error_message)
end
end

Expand Down