Class: Common::Client::Middleware::Response::CaseflowErrors

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/common/client/middleware/response/caseflow_errors.rb

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/common/client/middleware/response/caseflow_errors.rb', line 8

def on_complete(env)
  return if env.success?

  mapped_error = env[:body]['errors']&.first
  return if mapped_error.nil?

  # Caseflow does not generally populate a "code" so we
  # fall back to using the status as a code.
  env[:body]['code'] = mapped_error['code'] || mapped_error['status']
  env[:body]['detail'] = mapped_error['title']
  env[:body]['source'] = mapped_error['detail']
end