Centralized Error Handling and Middleware Errors
Hello, I'm coming from a Python/Flask background for backend development, and I am struggling in tanstack Start to handle errors in general.
In the flask world we can create something like this:
This sets up different global error handlers for different types of Exceptions. When an error is raised, I can log it,
and a structured error response (code, message, description) is returned to the frontend.
I'm struggling to find an equivalent approach here. Specifically:
1. Global Error Handling: How can I implement centralized error handling, similar to Flask's @app_errorhandler?
or any other way to catch different type of errors for different displays.
2. Middleware Error Responses: In authentication middleware, if a user is unauthorized/forbidden, I want to return a 401 or 403 response.
Currently, it seems I'm limited to redirects or throwing 500 errors. It would be nice to be able to setup the HTTP status code directly.
Also on the frontend side I'm struggling to catch efficiently the errors...
Thanks to anyone who can help 🙂
1 Reply
rising-crimson•6mo ago
we don't have centralized error handlers yet
but I would like to add them