def handle_http_exception_error(ex):
    """Handle http exception error."""
    logger.warning('%r %r, detail: %r', request.method, quote(request.path),
                   str(ex))
    if isinstance(ex, NotFound):
        error = RestfulApiNotExist()
    elif isinstance(ex, MethodNotAllowed):
        error = RequestMethodNotAllowed()
    else:
        logger.exception(ex)
        error = UnknownError('System error or http error.')
    res_body = {"error_code": error.error_code, "error_msg": error.message}
    return jsonify(res_body), error.http_code
Exemple #2
0
def before_request():
    """A function to run before each request."""
    if request.method not in settings.SUPPORT_REQUEST_METHODS:
        raise RequestMethodNotAllowed()