From 5eccdceb8413992e5086d81e4cee398b4236fad7 Mon Sep 17 00:00:00 2001 From: scossu Date: Mon, 6 May 2024 09:04:42 -0400 Subject: [PATCH] Add bad request debug handler. --- scriptshifter/rest_api.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scriptshifter/rest_api.py b/scriptshifter/rest_api.py index d7676cd..5ed4206 100644 --- a/scriptshifter/rest_api.py +++ b/scriptshifter/rest_api.py @@ -8,6 +8,7 @@ from smtplib import SMTP from flask import Flask, jsonify, render_template, request +from werkzeug.exceptions import BadRequest from scriptshifter import EMAIL_FROM, EMAIL_TO, SMTP_HOST, SMTP_PORT from scriptshifter.exceptions import ApiError @@ -46,6 +47,20 @@ def handle_exception(e: ApiError): }, e.status_code) +@app.errorhandler(BadRequest) +def handle_400(e): + if logging.DEBUG >= logging.root.level: + body = { + "debug": { + "form_data": request.form, + } + } + else: + body = "" + + return body, 400 + + @app.route("/", methods=["GET"]) def index(): return render_template(