Ejemplo n.º 1
0
def _check_and_get_response(response: Response, method: str) -> dict:
    """Checks the kraken response and if it's succesfull returns the result. If there
    is an error an exception is raised"""
    if response.status_code in (520, 525, 504):
        raise RecoverableRequestError('kraken', 'Usual kraken 5xx shenanigans')
    elif response.status_code != 200:
        raise RemoteError(
            'Kraken API request {} for {} failed with HTTP status '
            'code: {}'.format(
                response.url,
                method,
                response.status_code,
            ))

    result = rlk_jsonloads_dict(response.text)
    if result['error']:
        if isinstance(result['error'], list):
            error = result['error'][0]
        else:
            error = result['error']

        if 'Rate limit exceeded' in error:
            raise RecoverableRequestError('kraken', 'Rate limited exceeded')
        else:
            raise RemoteError(error)

    return result['result']
Ejemplo n.º 2
0
    def check_and_get_response(self, response, method):
        if response.status_code in (520, 525, 504):
            raise RecoverableRequestError('kraken', 'Usual kraken 5xx shenanigans')
        elif response.status_code != 200:
            raise ValueError(
                'Kraken API request {} for {} failed with HTTP status '
                'code: {}'.format(
                    response.url,
                    method,
                    response.status_code,
                ))

        result = rlk_jsonloads(response.text)
        if result['error']:
            if isinstance(result['error'], list):
                error = result['error'][0]
            else:
                error = result['error']

            if 'Rate limit exceeded' in error:
                raise RecoverableRequestError('kraken', 'Rate limited exceeded')
            else:
                raise ValueError(error)

        return result['result']