8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/gocardless_pro/middlewares/raise_gocardless_errors.rb', line 8
def on_complete(env)
if !(env.status == API_STATUS_NO_CONTENT || json?(env)) || API_ERROR_STATUSES.include?(env.status)
raise ApiError, generate_error_data(env)
end
return unless CLIENT_ERROR_STATUSES.include?(env.status)
json_body ||= JSON.parse(env.body) unless env.body.empty?
if json_body['error'].is_a?(String)
json_body['error'] = {
'message' => json_body['error'],
'status' => env.status,
}
end
error_type = json_body['error']['type']
error_class = error_class_for_status(env.status) || error_class_for_type(error_type)
raise(error_class, json_body['error'])
end
|