How to handle expected TRPCError #56
Unanswered
CapitaineToinon
asked this question in
Q&A
Replies: 2 comments
-
From https://trpc.io/docs/error-handling
{
"id": null,
"error": {
"message": "\"password\" must be at least 4 characters",
"code": -32600,
"data": {
"code": "BAD_REQUEST",
"httpStatus": 400,
"stack": "...",
"path": "user.changepassword"
}
}
} And from https://kit.svelte.dev/docs/load#errors import { error } from '@sveltejs/kit';
export const load = (async ({ params }) => {
const blog = await trpc(event).byId.query({ id: params.id });
if (blog.error) {
// process error
throw error(404, 'Not found');
}
return {
blog
};
}) satisfies PageLoad; |
Beta Was this translation helpful? Give feedback.
0 replies
-
Maybe this helps? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello 👋
I have a simple router like this with dummy data:
And a simple load function like so:
I was wondering if this package has a way to handle expected TRPCErrors? In this case, if the user goes to
/blog/1000
and if blog withid
1000 does not exists, then my router will throw a TRPCError with status code 404. I would like to be able to automatically convert this to a sveltekiterror
call in order to trigger my+error.svelte
page as this error is expected but instead it will just go the unexpected errors. I know I can just handle the error manually in my load function but I'm expected to use trpc in many loaders and I would prefer a better way to avoid repeated code everywhere.Is there any out of the box solution with this package? Could I create a simple wrapper function? Or maybe are there good reasons for me not to do what I'm trying to do?
Feedback welcome, thanks!
🤠
Beta Was this translation helpful? Give feedback.
All reactions