Module: Audd::ResponseParser

Defined in:
lib/audd/response_parser.rb

Overview

Turns a raw HTTP response into a decoded success body, or raises the matching Audd::Error subclass.

Constant Summary collapse

HTTP_CLIENT_ERROR_FLOOR =
400
DEPRECATED_PARAMS_CODE =

Code 51 is a soft deprecation: the server fulfilled the request but is warning about a parameter. When a result came back with it, warn and carry on rather than raising.

51

Class Method Summary collapse

Class Method Details

.decode!(response) ⇒ Hash

Returns the parsed status: "success" body.

Returns:

  • (Hash)

    the parsed status: "success" body



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/audd/response_parser.rb', line 21

def decode!(response)
  body = parse_json(response)
  return handle_deprecation(body) if deprecation_pass_through?(body)

  case body["status"]
  when "success" then body
  when "error" then raise_api_error(body, response)
  else
    raise ServerError.new(
      error_code: 0,
      error_message: "Unexpected response status: #{body["status"].inspect}",
      http_status: response.status,
      request_id: response.request_id,
      raw_response: body
    )
  end
end