AggregateError object takes multiple iterable
Error instances and wraps them in a single error.
How to throw an AggregateError?
How to catch an AggregateError?
Promise.anyall errors from all async operations can be caught with a single error object. Helps you provide detailed error messages.
- If you are an API developer, you can collect all validation errors in an array for a call and report it once, instead of going for a round trip. Most of you may already do it with different ways, AggregateError makes it easy by instantiating one object for each request and lets you collect many errors from ACLs, Authentication, Validation etc.
- You don't have to interrupt an execution in the middle by throwing an Error object. You can let it pass and collect all errors in an array and finally deal with the errors if at all required.
Functions with a single parameter, the value of a parameter can be piped into a function.
Let's take an underscore.js library's example,
- As it takes only one parameter, do they allow more complex syntax? Like,
2. Can they play a role in async/await functions? Imagine how clean the code will look.
3. Can they also play a role for generator functions?
- AggregateError helps you collect all Error objects as one object.
- Pipeline Operator makes calling functions with single parameter clean and helps you chain methods.