Skip to content

Commit 1831771

Browse files
committed
Add response status in error message
1 parent be551a7 commit 1831771

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

lib/adyen/client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def call_adyen_api(service, action, request_data, headers, version, _with_applic
227227
when 422
228228
raise Adyen::ValidationError.new('Validation error', request_data, response.body)
229229
when 500..599
230-
raise Adyen::ServerError.new('Internal server error', request_data, response.body)
230+
raise Adyen::ServerError.new("Internal server error - status #{response.status}", request_data, response.body)
231231
end
232232

233233
# delete has no response.body (unless it throws an error)

spec/client_spec.rb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,5 +352,27 @@
352352
expect(error.response[:errorCode]).to eq('30_011')
353353
end
354354
end
355-
355+
356+
it 'raises FormatError on 500 response and checks content' do
357+
client = Adyen::Client.new(api_key: 'api_key', env: :test)
358+
mock_faraday_connection = double(Faraday::Connection)
359+
error_body = {
360+
status: 500,
361+
errorCode: "999",
362+
message: "Unexpected error",
363+
errorType: "server error"
364+
}
365+
mock_response = Faraday::Response.new(status: 500, body: error_body)
366+
367+
allow(Faraday).to receive(:new).and_return(mock_faraday_connection)
368+
allow(mock_faraday_connection).to receive_message_chain(:headers, :[]=)
369+
allow(mock_faraday_connection).to receive(:post).and_return(mock_response)
370+
371+
expect {
372+
client.checkout.payments_api.payments({})
373+
}.to raise_error(Adyen::ServerError) do |error|
374+
expect(error.code).to eq(500)
375+
expect(error.msg).to eq('Internal server error - status 500')
376+
end
377+
end
356378
end

0 commit comments

Comments
 (0)