8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# 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?
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
|