exports.AppError = class AppError extends Error { constructor( settings = {} ) { settings.type ? super( `Domain Error: ${ settings.type }` ) : super( "Technical Error" ) ; this.name = "AppError"; this.type = ( settings.type || null ); this.detail = ( settings.detail || null ); this.rootCause = ( settings.rootCause || null ); this.extendedInfo = ( settings.extendedInfo || null ); Error.captureStackTrace( this, this.constructor ); } // --- // STATIC METHODS. // --- static is( error, ...typePrefixes ) { if ( ! ( ( error instanceof AppError ) && error.type ) ) { return( false ); } for ( const typePrefix of typePrefixes ) { if ( ( error.type === typePrefix ) || ( error.type.startsWith( typePrefix + "." ) ) ) { return( true ); } } return( false ); } static isDomainError( error ) { return( ( error instanceof AppError ) && error.type ); } }