Throw Validation error inside the procedure?
Is there an easy way to throw a validation error programmatically from inside the procedure?
I'm already pre-validating the input with a schema (Arktype) but then I need to add some additional validation to check uniqueness or other things with the DB or external API.
What I'd like to do is being able to use something like this inside my procedure.
This throws an INTERNAL_SERVER_ERROR, so my current workaround is to catch the ArkError and wrap it into a TRPCError BAD_REQUEST.
This feels kind of hacky, and I'd like to ensure this works as closely as the input validation as possible, so that my frontend can handle both cases similarly.
In this case if the URL I send is invalid, it shows under the field. If the URL is valid, but it already exists or is banned or whatever, I want it so show under the field as well.
2 Replies