public static function handleError(BadResponseException $exception)
    {
        $response_body = (string) $exception->getResponse()->getBody();
        $array_body = decode($response_body);

        $code = $exception->getResponse()->getStatusCode();

        $lookForKeys = ['message', 'code', 'error'];

        foreach ($lookForKeys as $key) {
            if (isset($array_body[$key])) {
                $message = $array_body[$key];
            }
        }

        if (!$message) {
            $message = 'unknown_error';
        }

        throw new JSONError($message, $code, $array_body);
    }