Browse Source

Merge branch 'main' into test

scossu 1 year ago
parent
commit
9da41d9530
1 changed files with 15 additions and 0 deletions
  1. 15 0
      scriptshifter/rest_api.py

+ 15 - 0
scriptshifter/rest_api.py

@@ -8,6 +8,7 @@ from os import environ, urandom
 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(