Example #1
0
def page_not_found(e):
    if wants_json_response():
        return api_error_response(404)
    else:
        title = "Lang&Code - Not Found"
        flash("Not Found or Under Construction: The page you are trying to view does not seem to exist." , "is-warning")
        return render_template("errors/not-found.html", title=title), 404
Example #2
0
def internal_error(error):
    db.session.rollback()  # rollback to keep the db data cleanly and correctly
    if wants_json_response():
        return api_error_response(500)
    return render_template(
        'errors/500.html'
    ), 500  # the second value of this return is the response status code, defaults 200.
Example #3
0
def internal_error(error):
    db.session.rollback()
    # return json format
    if wants_json_response():
        return api_error_response(500)
    # return html format
    return render_template('errors/500.html'), 500
Example #4
0
def not_found_error(error):
    # 根据http的内容协商结果,选择返回哪种格式的错误内容
    if wants_json_response():
        # 使用API接口中设计的错误返回,返回json格式内容
        return api_error_response(404)
    # 按照html格式渲染返回错误页面的
    return render_template('errors/404.html'), 404
def internal_error(error):
    """Handle 500 internal server error when an application error occures"""
    db.session.rollback()
    if wants_json_response():
        return api_error_response(500)
    return render_template('errors/error.html',
                           title=_('500 - Internal Server Error')), 500
Example #6
0
def internal_server_error(e):
    db.session.rollback()
    if wants_json_response():
        return api_error_response(500)
    title = "Lang&Code - Internal Server Error occured."
    flash("Internal Server Error: The server has been fed invalid data or is undergoing maintance." , "is-danger")
    return render_template("errors/not-found.html", title=title), 500
Example #7
0
def not_found_error(error):
    """
    Returns 404 error code response in JSON or HTML format, depending on
    client preference.
    """
    if wants_json_response():
        return api_error_response(404)
    return render_template('errors/404.html'), 404
def forbidden_error(error):
    """Handle 403 forbidden errors when user goes to page he/she is not allowed
    to browse to
    """
    if wants_json_response():
        return api_error_response(403)
    return render_template('errors/error.html',
                           title=_('403 - Forbidden')), 403
Example #9
0
def page_not_found(e):
    """Returns 404 error if page not found."""

    if wants_json_response():
        return api_error_response(404)

    title = "Page Not Found"
    return render_template("errors/404.html", title=title), 404
Example #10
0
def forbidden(e):
    """Returns 403 error if user lacks permissions."""

    if wants_json_response():
        return api_error_response(403)

    title = "Forbidden"
    return render_template("errors/403.html", title=title), 403
Example #11
0
def internal_error(error):
    '''
    500 errors could be a database error. To make sure any failed database sessions do not interfere with any database accesses triggered by the template, issue session rollback
    '''
    db.session.rollback()
    if wants_json_response():
        return api_error_response(500)
    return render_template('errors/500.html'), 500
Example #12
0
def not_found_error(error):
    print("-----URL NOT FOUND-----")

    if wants_json_response():
        print("-----returning json error")
        return api_error_response(404)

    print("--------returning html error")
    return render_template('errors/404.html'), 404
Example #13
0
def internal_service_error(e):
    """Returns 500 error if internal service error."""

    db.session.rollback()
    if wants_json_response():
        return api_error_response(500)

    title = "Internal Service Error"
    return render_template("errors/500.html", title=title), 500
Example #14
0
def internal_error(error):
    """
    Returns 500 error code response in JSON or HTML format, depending on
    client preference.
    """
    db.session.rollback()
    if wants_json_response():
        return api_error_response(500)
    return render_template('errors/500.html'), 500
Example #15
0
def not_found_error(error):
    """
        Function to display specific page for 400 error
    """

    if wants_json_response():

        return api_error_response(404)

    return render_template("errors/error_404.html"), 404
Example #16
0
def internal_error(error):  #Not able to catch this error
    print("===================INTERNAL ERROR CATCHED====================")
    db.session.rollback()

    if wants_json_response():
        print("-----returning json error")
        return api_error_response(500)

    print("-----returning html error")
    return render_template('errors/500.html'), 500
Example #17
0
def not_found_error(error):
    if wants_json_response():
        return api_error_response(404)
    if current_user.is_authenticated:
        #current_id = current_user.get_id()
        #user, = User.search([('id','=',current_id)])
        username_id = current_user.get_id()
        user, = User.search([('id','=',username_id)])
        print("USER",str(user))
        return render_template('errors/404.html',user=user), 404
    return render_template('errors/404.html'), 404
Example #18
0
def internal_error(error):
    """
        Function to display specific page for 500 error
    """

    db.session.rollback()

    if wants_json_response():

        return api_error_response(500)

    return render_template("errors/error_500.html"), 500
Example #19
0
def internal_error(error):
    db.session.rollback()

    current_app.logger.debug("error occurred: %s" % error)
    try:
        code = error.code
        errmsg = "error occurred: %s" % error
        # if code == 400:
        #     return render_template('400.html')
        # elif code == 401:
        #     return render_template('401.html')
        # else:
        #     return render_template('error.html')
        etype, value, tb = sys.exc_info()
    # print traceback.print_exception(etype, value, tb)

    except Exception as error:
        current_app.logger.debug('exception is %s' % error)
    finally:
        if wants_json_response():
            return api_error_response(500)
        return render_template('errors/500.html', code=code, msg=errmsg), 500
Example #20
0
def unauthorized(e):
    if wants_json_response():
        return api_error_response(401)
    title = "Lang&Code - Unauthorized"
    flash("Unauthorized: You do not have enough permission to access this page. Please login with proper credentials." , "is-danger")
    return render_template("errors/not-found.html", title=title), 401
Example #21
0
def bad_request(e):
    if wants_json_response():
        return api_error_response(500)
    title = "Lang&Code - Bad Request"
    flash("Bad Request" , "is-danger")
    return render_template("errors/not-found.html", title=title), 400
Example #22
0
def forbidden(e):
    if wants_json_response():
        return api_error_response(403)
    title = "Lang&Code - Forbidden"
    flash("Forbidden to access this page. Needs advanced permissions." , "is-danger")
    return render_template("errors/not-found.html", title=title), 403
Example #23
0
def method_not_allowed(e):
    if wants_json_response():
        return api_error_response(405)
    title = "Method Not Allowed"
    flash("The issued method is not allowed with this endpoint.")
    return render_template("errors/not-found.html", title=title), 405
Example #24
0
def token_auth_error(status):
    return api_error_response(status)
Example #25
0
def basic_auth_error(status):
    return api_error_response(status)
Example #26
0
def internal_error(error):
    db.session.rollback(
    )  #resets the session to a clean slate to ensure everything continues to work properly in the db
    if wants_json_response():
        return api_error_response(500)
    return render_template('errors/500.html'), 500
Example #27
0
def not_found_error(error):
    return api_error_response(404)
Example #28
0
def internal_error(error):
    db.session.rollback()
    if wants_json_response():
        return api_error_response(500)
    return render_template('errors/500.html'), 500
Example #29
0
def not_found_error(error):
    if wants_json_response():
        return api_error_response(404)
    return render_template('errors/404.html'), 404
Example #30
0
def not_found_error(error):
    if wants_json_response():
        return api_error_response(404)
    return render_template('errors/404.html'), 404
Example #31
0
def internal_error(error):
    if wants_json_response():
        return api_error_response(500)
    return render_template('errors/500.html'), 500
Example #32
0
def internal_error(error):
    # db.session.rollback()
    if wants_json_response():
        return api_error_response(500)
    return render_template('errors/500.html'), 500