示例#1
0
def process_response(response):
    try:
        body = response.json()
    except ValueError as decode_error:
        api_error_exception = ApiResponseDecodeError(
            "JSON decoding failed: {}".format(decode_error))
        raise api_error_exception

    if not response.ok:
        if "error_list" in body:
            for error in body["error_list"]:
                if error["code"] == "user-not-ready":
                    if "has not signed agreement" in error["message"]:
                        raise AgreementNotSigned
                    elif "missing namespace" in error["message"]:
                        raise MissingUsername

            raise ApiResponseErrorList(
                "The api returned a list of errors",
                response.status_code,
                body["error_list"],
            )
        elif not body:
            raise ApiResponseError("Unknown error from api",
                                   response.status_code)

    return body
示例#2
0
def process_response(response):
    try:
        body = response.json()
    except ValueError as decode_error:
        api_error_exception = ApiResponseDecodeError(
            'JSON decoding failed: {}'.format(decode_error), )
        raise api_error_exception

    if not response.ok:
        if 'error_list' in body:
            for error in body['error_list']:
                if error['code'] == 'user-not-ready':
                    if 'has not signed agreement' in error['message']:
                        raise AgreementNotSigned
                    elif 'missing namespace' in error['message']:
                        raise MissingUsername

            raise ApiResponseErrorList('The api returned a list of errors',
                                       response.status_code,
                                       body['error_list'])
        else:
            raise ApiResponseError('Unknown error from api',
                                   response.status_code)

    return body
示例#3
0
    def process_response(self, response):
        try:
            body = response.json()
        except ValueError as decode_error:
            api_error_exception = ApiResponseDecodeError(
                'JSON decoding failed: {}'.format(decode_error),
            )
            raise api_error_exception

        if not response.ok:
            if 'error_list' in body or 'error-list' in body:
                # V1 and V2 error handling
                error_body = (
                    body['error_list']
                    if 'error_list' in body else body['error-list']
                )
                api_error_exception = ApiResponseErrorList(
                    'The api returned a list of errors',
                    response.status_code,
                    error_body
                )
                raise api_error_exception
            else:
                raise ApiResponseError(
                    'Unknown error from api',
                    response.status_code
                )

        return body
示例#4
0
def process_response(response):
    if not response.ok:
        raise ApiResponseError("Unknown error from api", response.status_code)

    try:
        body = response.json()
    except ValueError as decode_error:
        api_error_exception = ApiResponseDecodeError(
            "JSON decoding failed: {}".format(decode_error))
        raise api_error_exception

    return body
示例#5
0
    def _process_response(self, response):
        try:
            body = response.json()
        except ValueError as decode_error:
            api_error_exception = ApiResponseDecodeError(
                "JSON decoding failed: {}".format(decode_error))
            raise api_error_exception

        if not response.ok:
            if body.get("success") is False:
                api_error_exception = ApiResponseErrorList(
                    "The api returned a list of errors",
                    body["errors"][0]["code"],
                    map(lambda error: error["message"], body["errors"]),
                )

                raise api_error_exception
            else:
                raise ApiResponseError("Unknown error from api", 500)

        return body
示例#6
0
    def process_response(self, response):
        try:
            body = response.json()
        except ValueError as decode_error:
            api_error_exception = ApiResponseDecodeError(
                "JSON decoding failed: {}".format(decode_error))
            raise api_error_exception

        if not response.ok:
            if "error_list" in body or "error-list" in body:
                # V1 and V2 error handling
                error_body = (body["error_list"]
                              if "error_list" in body else body["error-list"])
                api_error_exception = ApiResponseErrorList(
                    "The api returned a list of errors",
                    response.status_code,
                    error_body,
                )
                raise api_error_exception
            else:
                raise ApiResponseError("Unknown error from api",
                                       response.status_code)

        return body