S
SolidJS3w ago
Don

server function error handling

Is there any error handling in server functions? Because if an RPC gets called and throws an error, it gets stringified and returned with a 200 status code.
export const serverFnCommentAdd = query(
async (args: typeof commentInsertSchema.static) => {
"use server";
return (await rpc.api.comment.post(args)).data!;
},
"comments-add",
);
export const serverFnCommentAdd = query(
async (args: typeof commentInsertSchema.static) => {
"use server";
return (await rpc.api.comment.post(args)).data!;
},
"comments-add",
);
5 Replies
Madaxen86
Madaxen863w ago
Uncaught errors are handled with the ErrorBoundary component. But inside server functions you can catch handle the error yourself.
Don
DonOP3w ago
yes but I want to throw the error again but its always status code 200
Madaxen86
Madaxen863w ago
That is related to your rpc. What is that doing? And if you are modifying data in a db you should probably use an action instead of query
OrJDev
OrJDev3w ago
try { return myAction() } catch { return new Response(…) } you could just return a response and set any status code you wnat
OrJDev
OrJDev3w ago
MediaKit
error$ | MediaKit
error$ Utility
MediaKit
Error Handling | MediaKit
How To Handle Client Side Errors
Want results from more Discord servers?
Add your server