topkat-utils
Version:
A comprehensive collection of TypeScript/JavaScript utility functions for common programming tasks. Includes validation, object manipulation, date handling, string formatting, and more. Zero dependencies, fully typed, and optimized for performance.
47 lines (46 loc) • 2.19 kB
TypeScript
import { ErrorOptions } from './types';
export { type ErrorOptions } from './types';
export declare function errIfNotSet(objOfVarNamesWithValues: Record<string, any>): void;
export declare function err500IfNotSet(objOfVarNamesWithValues: Record<string, any>): void;
export declare function errIfEmptyOrNotSet(objOfVarNamesWithValues: Record<string, any>): void;
export declare function err500IfEmptyOrNotSet(objOfVarNamesWithValues: Record<string, any>): void;
export declare function errXXXIfNotSet(errCode: number, checkEmpty: boolean, objOfVarNamesWithValues: Record<string, any>): void;
export declare function err422IfNotSet(o: Record<string, any>): void;
/** Works natively with sync AND async functions */
export declare function tryCatch<T>(callback: () => T, onErr?: Function): T;
export declare const failSafe: typeof tryCatch;
export declare class DescriptiveError<ExpectedOriginalError = any> extends Error {
/** Full error infos, extra infos + message and code...etc as object */
errorDescription: {
/** used to uniquely identify the error */
id: string;
/** Http error code if any */
code: number;
message: string;
/** The parent error if any */
originalError?: Error | Record<string, any> | DescriptiveError;
[k: string]: any;
};
/** The parent error if any */
originalError: ExpectedOriginalError;
/** used to uniquely identify the error */
id: string;
/** Http code. Eg: 404, 403... */
code?: number;
message: string;
options: ErrorOptions;
/** Logging of the error is async, unless disabled, so that it wait one frame to allow to log it manually */
hasBeenLogged: boolean;
isAxiosError: boolean;
doNotLog: boolean;
logs: string[];
readonly isDescriptiveError = true;
/** This for client usage, and is not used by DescriptiveError. It can be used to mark an error as handled by your system. */
isHandled: boolean;
constructor(message: string, options?: ErrorOptions);
/** Compute extraInfos and parse options */
parseError(forCli?: boolean): string[];
log(): void;
toString(): string;
toJSON(): string;
}