#middleware is throwing an error which isn't visible on server but on client console

8 messages · Page 1 of 1 (latest)

spark sparrow
#

I've created a very basic server function for a todo list app (currently stored in a colocated json file) and a very basic middleware, which throws an error if user isn't authenticated, but even though the middleware only has a .server method defined, i'm seeing the error and the error message on the client, and not in the dev server logs

proud bloom
#

Try using console.log to see if it logs from the client or the server?

spark sparrow
#

i'm getting logs in the server, but shouldn't the thrown error also come in the server? why/how is it going it to the client?

proud bloom
#

Client (React) receives an error response

When you call a server function (for example, via useServerFn, createServerFn, or route loader), the client receives an error response => TanStack Start automatically throws an error in the hook.

Result: you see the error displayed on the client console (and usually in the UI if you have an error boundary or .catch()).

flat mural
#

throwing an error in a server function or function middleware will cause this error to be serializer and sent to the client

spark sparrow
#

oh okay!

#

thanks @flat mural and @proud bloom