jack
jack15mo ago

error route always getting 500 from trpc error? (next13/approuter)

I've got this condition for throwing in my trpc procedure:
if (!userClerkProfile) {
console.log("throwing"); // -> this is logging
throw new TRPCError({
code: "NOT_FOUND",
message: `Couldn't find the user with @${input.username}`,
});

if (!userClerkProfile) {
console.log("throwing"); // -> this is logging
throw new TRPCError({
code: "NOT_FOUND",
message: `Couldn't find the user with @${input.username}`,
});

and on client I have a next13 error.tsx route, in which I do:
const ErrorViewMap = {
[TRPC_ERROR_MAP.NOT_FOUND]: UsernameNotFoundErrorView,
DEFAULT: () => <p>Unexpected error, please try again</p>,
};

export default function ProfilePageError({
error,
reset,
}: PropsProfilePageError) {
const errorCode = getHTTPStatusCodeFromError(error);
const ErrorView = ErrorViewMap[errorCode] ?? ErrorViewMap.DEFAULT;

return <ErrorView message={"stock message"} resetFn={reset} />;
}
const ErrorViewMap = {
[TRPC_ERROR_MAP.NOT_FOUND]: UsernameNotFoundErrorView,
DEFAULT: () => <p>Unexpected error, please try again</p>,
};

export default function ProfilePageError({
error,
reset,
}: PropsProfilePageError) {
const errorCode = getHTTPStatusCodeFromError(error);
const ErrorView = ErrorViewMap[errorCode] ?? ErrorViewMap.DEFAULT;

return <ErrorView message={"stock message"} resetFn={reset} />;
}
errorCode is always 500 when we throw from that condition. No matter the code I pass when I throw
3 Replies
jack
jackOP15mo ago
Bumping this. Cant figure it out for the life of me
João Bezerra
João Bezerra3mo ago
I'm running into the same problem. Regardless of the code I pass to the constructor of TRPCError when throwing I still get INTERNAL_SERVER_ERROR code on the client. Can anyone help? @jack Were you able to figure out a solution?
jack
jackOP3mo ago
Lol I forgot about this entirely For what it’s worth I’ve tried rewriting this from scratch in app router, then Astro, then Solid and still not finished the app since I made this post 😂

Did you find this page helpful?