Create an error from multiple errors
94
Build a custom error class for validation scenarios that can aggregate multiple validation failures into a single throwable error. The error should be compatible with standard JavaScript error handling patterns and maintain proper error interface compliance.
You need to create a ValidationError class that:
message property (and optionally other metadata like field or code)failures propertyfailures property should return the validation errors but prevent external modification of the internal error listfailures property @test@generates
/**
* Custom error class for aggregating validation failures
*/
class ValidationError extends Error {
/**
* @param {Array} failures - Array of validation failures (Error, object, or string)
* @throws {TypeError} If failures is not an array
*/
constructor(failures);
/**
* The error name, always 'ValidationError'
* @type {string}
*/
name;
/**
* Read-only access to the validation failures
* @type {Error[]}
*/
get failures();
}
export default ValidationError;Provides functionality for creating errors from multiple errors with proper error normalization and standard Error interface compliance.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/npm-aggregate-errordocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9