nani
Version:
Better error handling for Node
30 lines (29 loc) • 1.33 kB
TypeScript
import { ErrorPredicate } from "./error-predicate";
/**
* Normalizes an ErrorPredicate or Error constructor to an ErrorPredicate.
*
* @remarks
* This internal function is used to support various signatures of `findCause`
* and `filterCauses`. If the provided predicate function is an Error
* contructor, this function returns a new predicate which checks if `is`
* returns true with that constructor and the provided instance. Otherwise, this
* simply returns the predicate function as-is.
*
* @param predicate - Predicate function to normalize.
* @returns Normalized predicate function.
*/
export declare function normalizePredicate(predicate: ErrorPredicate | Function): ErrorPredicate;
/**
* Internal function which is part of the implementation of `find`.
* @param err - Error instance to search.
* @param predicate - Normalized predicate function.
* @returns First matching error, or null if none is found.
*/
export declare function findByPredicate(err: Error, predicate: ErrorPredicate): Error | null;
/**
* Internal function which is part of the implementation of `filter`.
* @param err - Error instance to search.
* @param predicate - Normalized predicate function.
* @returns Array of matched errors.
*/
export declare function filterByPredicate(err: Error, predicate: ErrorPredicate): Error[];