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](https://answer-overflow-discord-attachments.s3.amazonaws.com/1227026506119647363/Screenshot_2024-04-08_at_15.44.26.png)
9 Replies
Yes you aren’t hitting the tRPC endpoint
I am though, I can debug through the entire thing -> then something weird happens after throwing from inside
What does the response say?
Solution![No description](https://answer-overflow-discord-attachments.s3.amazonaws.com/1227036298636824617/Screenshot_2024-04-08_at_16.23.39.png)
I solved it through returning the error locally instead of throwing it
![No description](https://answer-overflow-discord-attachments.s3.amazonaws.com/1227036298636824617/Screenshot_2024-04-08_at_16.23.39.png)
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
I think that what happened is that when I throw the error the endpoint either returns null or nothing at all
Umm. That wouldnt be
Unexpected token '<', "<!DOCTYPE "... is not valid JSON
tho. idkthis was the code previous
![No description](https://answer-overflow-discord-attachments.s3.amazonaws.com/1227037905466163260/Screenshot_2024-04-08_at_16.30.08.png)
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