(self, query, req, exc)
Log :exc:`requests.exceptions.HTTPError`, converting to
        GraphQL's ``{"data": null, "errors": [{"message": str(exc)...}]}``

        :param query: the GraphQL query that triggered the result.
        :type query: str

        :param req: :class:`requests.Request` instance that was opened.
        :type req: :class:`requests.Request`

        :param exc: :exc:`requests.exceptions.HTTPError` instance
        :type exc: :exc:`requests.exceptions.HTTPError`

        :return: GraphQL-compliant dict with keys ``data`` and ``errors``.
        :rtype: dict
Log :exc:`requests.exceptions.HTTPError`, converting to
        GraphQL's ``{"data": null, "errors": [{"message": str(exc)...}]}``
Log : exc : requests . exceptions . HTTPError converting to GraphQL s { data : null errors : [ { message : str ( exc ) ... } ] }
def _log_http_error(self, query, req, exc):
        '''Log :exc:`requests.exceptions.HTTPError`, converting to
        GraphQL's ``{"data": null, "errors": [{"message": str(exc)...}]}``

        :param query: the GraphQL query that triggered the result.
        :type query: str

        :param req: :class:`requests.Request` instance that was opened.
        :type req: :class:`requests.Request`

        :param exc: :exc:`requests.exceptions.HTTPError` instance
        :type exc: :exc:`requests.exceptions.HTTPError`

        :return: GraphQL-compliant dict with keys ``data`` and ``errors``.
        :rtype: dict
        '''
        self.logger.error('log_error - %s: %s', req.url, exc)
        for h in sorted(exc.response.headers):
            self.logger.info('Response header: %s: %s', h,
                             exc.response.headers[h])

        body = exc.response.text
        content_type = exc.response.headers.get('Content-Type', '')
        self.logger.info('Response [%s]:\n%s', content_type, body)
        if not content_type.startswith('application/json'):
            return {'data': None, 'errors': [{
                'message': str(exc),
                'exception': exc,
                'status': exc.response.status_code,
                'headers': exc.response.headers,
                'body': body,
            }]}
        else:
            # GraphQL servers return 400 and {'errors': [...]}
            # if only errors was returned, no {'data': ...}
            try:
                data = json.loads(body)
            except json.JSONDecodeError as exc:
                return self._log_json_error(body, exc)

            if isinstance(data, dict) and data.get('errors'):
                data.update({
                    'exception': exc,
                    'status': exc.response.status_code,
                    'headers': exc.response.headers,
                })
                return self._log_graphql_error(query, data)
            return {'data': None, 'errors': [{
                'message': str(exc),
                'exception': exc,
                'status': exc.response.status_code,
                'headers': exc.response.headers,
                'body': body,
            }]}
def _log_http_error ( self , query , req , exc ) : self . logger . error ( 'log_error - %s: %s' , req . url , exc ) for h in sorted ( exc . response . headers ) : self . logger . info ( 'Response header: %s: %s' , h , exc . response . headers [ h ] ) body = exc . response . text content_type = exc . response . headers . get ( 'Content-Type' , '' ) self . logger . info ( 'Response [%s]:\n%s' , content_type , body ) if not content_type . startswith ( 'application/json' ) : return { 'data' : None , 'errors' : [ { 'message' : str ( exc ) , 'exception' : exc , 'status' : exc . response . status_code , 'headers' : exc . response . headers , 'body' : body , } ] } else : # GraphQL servers return 400 and {'errors': [...]} # if only errors was returned, no {'data': ...} try : data = json . loads ( body ) except json . JSONDecodeError as exc : return self . _log_json_error ( body , exc ) if isinstance ( data , dict ) and data . get ( 'errors' ) : data . update ( { 'exception' : exc , 'status' : exc . response . status_code , 'headers' : exc . response . headers , } ) return self . _log_graphql_error ( query , data ) return { 'data' : None , 'errors' : [ { 'message' : str ( exc ) , 'exception' : exc , 'status' : exc . response . status_code , 'headers' : exc . response . headers , 'body' : body , } ] }