container.ts
Version:
Modular application framework
58 lines (57 loc) • 2.09 kB
TypeScript
/** Error chain data type. */
export interface IErrorChain {
name: string;
value?: any;
}
/** Serialised error chain item type. */
export interface IErrorChainItem extends IErrorChain {
stack: string;
message?: string;
errno?: number;
code?: string;
path?: string;
syscall?: string;
}
/** Serialised error chain items. */
export interface IErrorChainSerialised {
ErrorChain: IErrorChainItem[];
}
/** Error chain error names. */
export declare enum EErrorChainError {
Serialise = "ErrorChainError.Serialise",
Deserialise = "ErrorChainError.Deserialise"
}
/**
* ErrorChain class.
* Serialisable, chained errors utility.
*/
export declare class ErrorChain {
/** Returns true if error instance of ErrorChain. */
static isErrorChain(error: any): error is ErrorChain;
/** Returns true if error instance of Error or ErrorChain */
static isError(error: any): error is Error | ErrorChain;
/** Returns name representation of error argument. */
static errorName(error: any): string;
/**
* Construct error message from name, data and optional cause.
* If data is a plain object it will be serialised into a JSON string.
*/
static messageConstructor(data: IErrorChain, cause?: ErrorChain | Error): string;
/** Return serialisable object of generic error data. */
static serialiseError(error: any): IErrorChainItem;
/** Return deserialised ErrorChain instance of serialised data. */
static deserialise(serialised: IErrorChainSerialised): ErrorChain | undefined;
readonly name: string;
readonly stack?: string;
readonly message?: string;
readonly value?: any;
readonly cause?: ErrorChain | Error;
/** Used for isErrorChain static method. */
protected readonly isErrorChain = true;
constructor(data: IErrorChain, cause?: ErrorChain | Error);
toString(): string;
/** Join chained error names with a separator. */
joinNames(separator?: string): string;
/** Return serialised data for this chained error. */
serialise(): IErrorChainSerialised;
}