Throwing something other than `Unexpected token '<', "<!DOCTYPE "... is not valid JSON`

I'm trying to do custom error handling but whatever I throw just ends up being `Unexpected token '<', "<!DOCTYPE "... is not valid JSON`` Am I doing something weird here?
No description
Solution:
I solved it through returning the error locally instead of throwing it
No description
Jump to solution
9 Replies
BeBoRE
BeBoRE2mo ago
Yes you aren’t hitting the tRPC endpoint
Samuel Barnholdt
I am though, I can debug through the entire thing -> then something weird happens after throwing from inside
BeBoRE
BeBoRE2mo ago
What does the response say?
Solution
Samuel Barnholdt
I solved it through returning the error locally instead of throwing it
No description
NeoBean
NeoBean2mo ago
i'm curious what happened here. If you're hitting trpc endpoint, trpc doesnt return html afaik. Or does it? Is this only happening in production/client? cloudflare/firewalls can return html page. Other than obviously the nextjs 404 page, which would mean youre indeed not hitting the endpoint
Samuel Barnholdt
I think that what happened is that when I throw the error the endpoint either returns null or nothing at all
NeoBean
NeoBean2mo ago
Umm. That wouldnt be Unexpected token '<', "<!DOCTYPE "... is not valid JSON tho. idk
Samuel Barnholdt
this was the code previous
No description
Samuel Barnholdt
yeah you're right, tried to find the argument to the JSON.parse that causes the bug but post throwing it's hard to follow
More Posts