Skip to content

Commit

Permalink
add error handler for RequestRedirect
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcusk19 committed Feb 28, 2024
1 parent b23a228 commit 4085663
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions endpoints/decorated.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

from flask import jsonify, make_response
from werkzeug.routing.exceptions import RequestRedirect

from app import app
from data import model
Expand Down Expand Up @@ -69,3 +70,12 @@ def handle_not_implemented_error(ex):
response = jsonify({"message": str(ex)})
response.status_code = 501
return response


@app.errorhandler(RequestRedirect)
def handle_bad_redirect(ex):
response = jsonify(
{"message": "bad path, there may be a trailing slash", "new_url": ex.new_url}
)
response.status_code = 308
return response

0 comments on commit 4085663

Please sign in to comment.