Class: Common::Client::Middleware::Response::PPMSParser
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Common::Client::Middleware::Response::PPMSParser
- Defined in:
- lib/common/client/middleware/response/ppms_parser.rb
Instance Method Summary collapse
Instance Method Details
#on_complete(env) ⇒ Object
8 9 10 |
# File 'lib/common/client/middleware/response/ppms_parser.rb', line 8 def on_complete(env) env.body = parse_body(env) end |
#parse_body(env) ⇒ Object (private)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/common/client/middleware/response/ppms_parser.rb', line 14 def parse_body(env) hash = JSON.parse(env.body) msg = hash.dig('error', 'message') case msg when /No Providers found/ # flag Not Found errors as success so the error doesn't bubble up env[:status] = 200 return [] when /An error has occurred/ # PPMS has encountered an internal error hash['error']['code'] = '_502' if hash['error']['code'].blank? # Set code so matches in exceptions.en.yml hash['error']['detail'] = hash['error']['message'] return hash['error'] end hash['value'] end |