Class: ChimeraHttpClient::Deserializer

Inherits:
Object
  • Object
show all
Defined in:
lib/chimera_http_client/deserializer.rb

Class Method Summary collapse

Class Method Details

.json_errorObject



14
15
16
17
18
19
20
# File 'lib/chimera_http_client/deserializer.rb', line 14

def json_error
  proc do |body|
    JSON.parse(body)
  rescue JSON::ParserError
    { "non_json_body" => body }
  end
end

.json_responseObject



22
23
24
25
26
27
28
# File 'lib/chimera_http_client/deserializer.rb', line 22

def json_response
  proc do |body|
    JSON.parse(body)
  rescue JSON::ParserError => e
    raise ::ChimeraHttpClient::JsonParserError, "Could not parse body as JSON: #{body}, error: #{e.message}"
  end
end