Class: PDC::Response::Parser
- Inherits:
-
Faraday::Response::Middleware
- Object
- Faraday::Response::Middleware
- PDC::Response::Parser
- Includes:
- Logging
- Defined in:
- lib/pdc/http/response/parser.rb
Overview
Converts body into JSON data, metadata and errors
Instance Method Summary collapse
Methods included from Logging
Instance Method Details
#parse(body) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/pdc/http/response/parser.rb', line 10 def parse(body) logger.debug "\n.....parse to json ....................................." logger.debug self.class logger.debug '... parsing' + body.to_s.truncate(55) begin json = MultiJson.load(body, symbolize_keys: true) rescue MultiJson::ParseError => e raise PDC::JsonParseError, e end { data: extract_data(json), # Always an Array errors: extract_errors(json), # metadata: (json) # a hash } end |