-
Notifications
You must be signed in to change notification settings - Fork 162
Description
Use case
Today when there is a parsing error (except when using safeParse) the error is thrown uncaught. This could be potentially undesired, as we may want to instead return a specific response to the request - I'm thinking specifically API Gateway here but others might benefit too (I just don't have those use cases).
Solution/User Experience
Add an error handler function to ParserOptions. In the decorator add a try/catch around the parse, and in the catch if the error handler function is present, use it and return its value otherwise rethrow the error.
This way we can handle errors JUST from the parse function, rather than some other upstream decorator catching ZodError (or whatever) from where exactly? maybe not just the parser.
Alternative solutions
Acknowledgment
- This feature request meets Powertools for AWS Lambda (TypeScript) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Python, Java, and .NET
Future readers
Please react with 👍 and your use case to help us understand customer demand.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status