How can i redirect a request with FastAPI if there is a HTTPException?
In Flask we can achieve that like this:
@app.errorhandler(404)
def handle_404(e):
if request.path.startswith('/api'):
return render_template('my_api_404.html'), 404
else:
return redirect(url_for('index'))
Or in Django we can use django.shortcuts:
from django.shortcuts import redirect
def view_404(request, exception=None):
return redirect('/')
How we can achieve that with FastAPI?