yourls/data.py
def _handle_api_error_with_json(http_exc, jsondata, response):
    """Handle YOURLS API errors.

    requests' raise_for_status doesn't show the user the YOURLS json response,
    so we parse that here and raise nicer exceptions.
    """
    if 'code' in jsondata and 'message' in jsondata:
        code = jsondata['code']
        message = jsondata['message']

        if code == 'error:noloop':
            raise YOURLSNoLoopError(message, response=response)
        elif code == 'error:nourl':
            raise YOURLSNoURLError(message, response=response)

    elif 'message' in jsondata:
        message = jsondata['message']
        raise YOURLSHTTPError(message, response=response)

    http_error_message = http_exc.args[0]
    raise YOURLSHTTPError(http_error_message, response=response)
def _handle_api_error_with_json(http_exc, jsondata, response):
    """Handle YOURLS API errors.

    requests' raise_for_status doesn't show the user the YOURLS json response,
    so we parse that here and raise nicer exceptions.
    """
    if 'code' in jsondata and 'message' in jsondata:
        code = jsondata['code']
        message = jsondata['message']

        if code == 'error:noloop':
            raise YOURLSNoLoopError(message, response=response)
        elif code == 'error:nourl':
            raise YOURLSNoURLError(message, response=response)

    elif 'message' in jsondata:
        message = jsondata['message']
        raise YOURLSHTTPError(message, response=response)

    http_error_message = http_exc.args[0]
    raise YOURLSHTTPError(http_error_message, response=response)
Handle YOURLS API errors.

    requests' raise_for_status doesn't show the user the YOURLS json response,
    so we parse that here and raise nicer exceptions.