diff --git a/scriptshifter/rest_api.py b/scriptshifter/rest_api.py index ccf5d0e..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( @@ -108,9 +123,7 @@ def transliterate_req(): except (NotImplementedError, ValueError) as e: return (str(e), 400) - return { - "output": out, "warnings": warnings, - "debug": {"form_data": request.form}} + return {"output": out, "warnings": warnings} @app.route("/feedback", methods=["POST"])