Skip to content

Commit 33be10a

Browse files
author
Eric Liu
committed
add global error handler for endpoints
1 parent a1833d4 commit 33be10a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

app/app.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@
5151
r = redis.from_url(os.getenv("REDIS_URL"), decode_responses=True)
5252

5353

54+
# Global error handler for unhandled exceptions
55+
@app.errorhandler(Exception)
56+
def handle_exception(e):
57+
logger.error(f"Unhandled exception in {request.endpoint}: {str(e)}", exc_info=True)
58+
return jsonify({"error": "An error occurred while processing your request."}), 500
59+
60+
5461
def validate_pow(nonce, data, difficulty):
5562
# Calculate the sha256 of the concatenated string of 32-bit X-Nonce header and raw body.
5663
# This calculation has to match the code on the client side, in index.html.

0 commit comments

Comments
 (0)