Skip to content

Commit 78adc48

Browse files
authored
Merge pull request #14 from Springest/expose_500_error_message
Expose error details on 500
2 parents d9b0ccc + e0b8d7f commit 78adc48

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/help_scout.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ def request(method, path, options)
240240
when HTTP_NOT_FOUND
241241
raise NotFoundError
242242
when HTTP_INTERNAL_SERVER_ERROR
243-
raise InternalServerError
243+
error_message = JSON.parse(last_response.body)["error"]
244+
raise InternalServerError, error_message
244245
when HTTP_TOO_MANY_REQUESTS
245246
retry_after = last_response.headers["Retry-After"]
246247
error_message = "Rate limit of 200 RPM or 12 POST/PUT/DELETE requests per 5 seconds reached. Next request possible in #{retry_after} seconds."

spec/helpscout_spec.rb

+14-3
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,22 @@
6565
end
6666

6767
context 'with a 500 status code' do
68-
it 'returns InternalServerError' do
68+
it 'returns InternalServerError with body' do
69+
expected_error_message = "Did not find any valid email for customer 1111"
70+
6971
url = 'https://api.helpscout.net/v1/conversations/1337.json'
70-
stub_request(:get, url).to_return(status: 500)
72+
stub_request(:post, url).
73+
to_return(
74+
status: 500,
75+
body: {
76+
"code": 500,
77+
"error": expected_error_message,
78+
}.to_json,
79+
)
7180

72-
expect { client.get_conversation(1337) }.to raise_error(HelpScout::InternalServerError)
81+
expect {
82+
client.create_thread(conversation_id: 1337, thread: {})
83+
}.to raise_error(HelpScout::InternalServerError, expected_error_message)
7384
end
7485
end
7586

0 commit comments

Comments
 (0)