Skip to content

Commit 496a818

Browse files
committed
Actually output validation errors in HelpScout::ValidationError
1 parent 12ee9c5 commit 496a818

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lib/help_scout.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def request(method, path, options)
234234
when HTTP_OK, HTTP_CREATED, HTTP_NO_CONTENT
235235
@last_response.parsed_response
236236
when HTTP_BAD_REQUEST
237-
raise ValidationError, last_response.parsed_response["message"]
237+
raise ValidationError, last_response.parsed_response["validationErrors"]
238238
when HTTP_FORBIDDEN
239239
raise ForbiddenError
240240
when HTTP_NOT_FOUND

spec/helpscout_spec.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
context 'with invalid input' do
2323
it 'returns validation errors' do
24-
data = { subject: "Help me!", customer: { email: "" } }
24+
data = { subject: "Help me!", customer: { email: "[email protected]" } }
2525

2626
url = 'https://api.helpscout.net/v1/conversations.json'
2727
stub_request(:post, url).
@@ -30,10 +30,19 @@
3030
headers: {
3131
'Content-Type' => 'application/json'
3232
},
33-
body: { error: "Input could not be validated", message: "Email is not valid" }.to_json
33+
body: {
34+
"error" => "Input could not be validated",
35+
"validationErrors" => [
36+
{
37+
"property" => "customer:email",
38+
"value" => "[email protected]",
39+
"message" => "Email is not valid"
40+
}
41+
]
42+
}.to_json
3443
)
3544

36-
expect { client.create_conversation(data) }.to raise_error(HelpScout::ValidationError, "Email is not valid")
45+
expect { client.create_conversation(data) }.to raise_error(HelpScout::ValidationError, '[{"property"=>"customer:email", "value"=>"[email protected]", "message"=>"Email is not valid"}]')
3746
end
3847
end
3948

0 commit comments

Comments
 (0)