Class: Lighthouse::Facilities::Middleware::Errors

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/lighthouse/facilities/middleware/errors.rb

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



7
8
9
10
11
# File 'lib/lighthouse/facilities/middleware/errors.rb', line 7

def on_complete(env)
  return if env.success?

  env.body = parse_body(env)
end

#parse_body(env) ⇒ Object (private)



15
16
17
18
19
20
21
22
23
24
# File 'lib/lighthouse/facilities/middleware/errors.rb', line 15

def parse_body(env)
  body = JSON.parse(env.body)
  message = body['message']

  body['detail'] = message
  body['code'] = env.status
  body['source'] = 'Lighthouse Facilities'

  body
end