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
11 Replies
BeBoRE
BeBoRE9mo ago
Yes you aren’t hitting the tRPC endpoint
Samuel Barnholdt
Samuel BarnholdtOP9mo ago
I am though, I can debug through the entire thing -> then something weird happens after throwing from inside
BeBoRE
BeBoRE9mo ago
What does the response say?
Solution
Samuel Barnholdt
I solved it through returning the error locally instead of throwing it
No description
NeoBean
NeoBean9mo 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
Samuel BarnholdtOP9mo ago
I think that what happened is that when I throw the error the endpoint either returns null or nothing at all
NeoBean
NeoBean9mo ago
Umm. That wouldnt be Unexpected token '<', "<!DOCTYPE "... is not valid JSON tho. idk
Samuel Barnholdt
Samuel BarnholdtOP9mo ago
this was the code previous
No description
Samuel Barnholdt
Samuel BarnholdtOP9mo ago
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
Aadarsha
Aadarsha7d ago
@Samuel Barnholdt did you fix the issue i got similar issues
Samuel Barnholdt
Samuel BarnholdtOP7d ago
@Aadarsha

Did you find this page helpful?