Skip to content

Commit

Permalink
Add bad request debug handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
scossu committed May 6, 2024
1 parent 2dda4ee commit e4449ff
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions scriptshifter/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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"])
Expand Down

0 comments on commit e4449ff

Please sign in to comment.