Class: Common::Client::Middleware::Response::MHVErrors

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

Overview

Faraday response middleware that checks the MHV service response for errors

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Faraday::Env

Checks the response for errors

Returns:

  • (Faraday::Env)


16
17
18
19
20
21
22
23
# File 'lib/common/client/middleware/response/mhv_errors.rb', line 16

def on_complete(env)
  return if env.success?
  return unless env[:body].is_a?(Hash)

  env[:body]['code'] = env[:body].delete('errorCode')
  env[:body]['detail'] = env[:body].delete('message')
  env[:body]['source'] = env[:body].delete('developerMessage')
end