How to throw a tRPC error if prisma query returns null

I tried the code in the photo but trpc query still returns null instead of raising an error.
12 Replies
iDarkLightning
You aren't awaiting You have a promise Your promise doesn't equal null
thevalorised
thevalorised2y ago
I realised and used .then but still can't catch the error using onError
thevalorised
thevalorised2y ago
iDarkLightning
That's not how that works, the thing that's throwing the tRPC error is the callback to .then not the query resolver Use async/await
thevalorised
thevalorised2y ago
Thank you so much Just leaving the code I ended up with just in case someone needs it in the future
thevalorised
thevalorised2y ago
iDarkLightning
Whyre you awaiting and then returning the promise Doesn't that add unnecessary overhead
Pod
Pod2y ago
I'm pretty sure prisma has some sort of findUniqueOrThrow
iDarkLightning
It does but tRPC will treat that as internal server error
Pod
Pod2y ago
Ah good to know
iDarkLightning
You can go into the error shape overrides and make it treat it as a not found though
thevalorised
thevalorised2y ago
Oh! I totally missed that, thanks.
Want results from more Discord servers?
Add your server