Server Fn error return types
Hello!
In createServerFn functions, should we return normal typescript errors (ie. Error object) or http errors like return new Response('Internal Server Error', { status: 500 }) ?
Thanks!
6 Replies
xenial-black•2mo ago
you should throw errors
those then need to be caught on the client side
genetic-orangeOP•2mo ago
thank you @Manuel Schiller , so all server fns result with an HTTP 200 on the client side right?
xenial-black•2mo ago
no, you will get a 500
you can change this be setting setResponseStatus before throwing
genetic-orangeOP•2mo ago
I tried to make use of setResponseStatus but it did not work.
And then, I followed the serialization-adapters example but again no luck. It keeps sending HTTP200 all the time.
xenial-black•2mo ago
are you throwing the error?
genetic-orangeOP•2mo ago
yes, like: