aito.client.v2.responses.unwrap_payload

aito.client.v2.responses.unwrap_payload(json: Dict, kind: str) Any

return the payload of a v2 response, whether or not it is enveloped

Parameters:
  • json (Dict) – the parsed response body

  • kind (str) – the result kind the called endpoint produces

Raises:

AitoV2ResponseError – the response carries a different kind

Returns:

json['data'] when enveloped, otherwise json itself

Return type:

Any

An enveloped response of the expected kind is unwrapped:

>>> unwrap_payload({'kind': 'estimate', 'data': {'value': 12.4}}, 'estimate')
{'value': 12.4}

A bare response — the rep1 compatibility shim’s v1 shape — is passed through rather than misread as a page of rows:

>>> unwrap_payload({'estimate': 12.4, 'why': {}}, 'estimate')
{'estimate': 12.4, 'why': {}}

A different kind is a real mismatch and raises:

>>> unwrap_payload({'kind': 'aggregate', 'data': {}}, 'estimate')
Traceback (most recent call last):
   ...
aito.client.v2.errors.AitoV2ResponseError: expected a 'estimate' response from Aito v2, got 'aggregate'