def prep_response(self, resp: Response, deserialize: bool = True) -> Response: """Populate the response with details and return it. :param deserialize: Deserialize the response body. :type deserialize: bool :param resp: HTTP response. :type resp: arango.response.Response :return: HTTP response. :rtype: arango.response.Response """ if deserialize: resp.body = self.deserialize(resp.raw_body) if isinstance(resp.body, dict): resp.error_code = resp.body.get("errorNum") resp.error_message = resp.body.get("errorMessage") else: resp.body = resp.raw_body http_ok = 200 <= resp.status_code < 300 resp.is_success = http_ok and resp.error_code is None return resp
def build_error_response(self, parent_response, body): """Build and return a bulk error response. :param parent_response: Parent response. :type parent_response: arango.response.Response :param body: Error response body. :type body: dict :return: Child bulk error response. :rtype: arango.response.Response """ response = Response( method=parent_response.method, url=parent_response.url, headers=parent_response.headers, status_code=parent_response.status_code, status_text=parent_response.status_text, raw_body=self.serialize(body), ) response.body = body response.error_code = body['errorNum'] response.error_message = body['errorMessage'] response.is_success = False return response