flask как не отображать страницу с ошибкой при использовании @ app.errorhandler (исключение), но продолжить работу приложения - PullRequest
0 голосов
/ 20 июня 2020

у меня

@app.errorhandler(Exception)
def unhandled(error):
    print(error)
    etype, value, tb = sys.exc_info()
    print(traceback.print_exception(etype, value, tb))
    logger.error("Exception %s" % traceback.format_exc())
    logger.error("Exception %s" % traceback.print_exception(etype, value, tb))
    logger.info("Exception %s" % traceback.format_exc())
    logger.info("Exception %s" % traceback.print_exception(etype, value, tb))
    print(traceback.format_exc())
    return None

@app.route('/')
def index():
    logger.info("A %s- B: %s" % project_dict)   # raise exception 
    a = 1
    b = 2
    c = 3

проблема в том, что я не могу использовать эту функцию, чтобы прервать поток вызывающего обработчика @ app.route ('/') только для печати в журнал и продолжения

a = 1
 b = 2
 c = 3

1 Ответ

0 голосов
/ 20 июня 2020

Что вы думаете об интеграции возможного ошибочного выполнения в блок try-except?

# This code is never executed due to an error that occurs within 
# the try-except block in the route `index`.
@app.errorhandler(Exception)
def unhandled(error):
    return make_response('Internal Server Error', 400)

@app.route('/')
def index():
    try:
       # Your code that may throw an error.
       raise Exception('something went wrong') # raise exception
    except Exception as exc: 
       # Handle exception here!
       pass 
    else:
       # This code is executes if no exception occurs.
       pass 
    finally:
       # This code is executed despite an exception.
       pass 
    # ...
...