17 lines
555 B
Python
17 lines
555 B
Python
|
from flask import jsonify
|
||
|
import traceback
|
||
|
from .webhook import send_error_webhook
|
||
|
|
||
|
def handle_exception(app, error):
|
||
|
error_message = str(error)
|
||
|
error_type = type(error).__name__
|
||
|
stack_trace = traceback.format_exc()
|
||
|
|
||
|
app.logger.error(f'Unhandled Exception: {error_type} - {error_message}\n{stack_trace}')
|
||
|
|
||
|
send_error_webhook(error_message, error_type, stack_trace)
|
||
|
|
||
|
return jsonify(error=error_message), 500
|
||
|
|
||
|
def register_error_handlers(app):
|
||
|
app.register_error_handler(Exception, lambda e: handle_exception(app, e))
|