@napp/exception
Version:
common exception. node application common library. serialization error
44 lines (43 loc) • 1.42 kB
TypeScript
export type ExceptionType = 'Validation' | 'Authentication' | 'Authorization' | 'NotFound' | 'Conflict' | 'Timeout' | 'TooManyRequests' | 'Unsupported' | 'Database' | 'Network' | 'ServiceUnavailable' | 'Internal' | 'Unknown' | (string & {});
export interface IException {
message: string;
type?: string;
code?: string;
cause?: IException;
data?: any;
isOperational?: boolean;
}
export interface IExceptionParser {
parse(err: any): Exception | false;
}
export interface ExceptionOption {
type?: ExceptionType;
code?: string;
cause?: any;
source?: any;
data?: any;
isOperational?: boolean;
httpStatus?: number;
}
export declare class Exception extends Error implements IException {
type?: ExceptionType;
code?: string;
cause?: Exception;
stack?: string;
source?: any;
data?: any;
isOperational?: boolean;
httpStatus?: number;
constructor(message: string, opt?: ExceptionOption);
setErrorType(type: ExceptionType): this;
setErrorCode(code: string): this;
setCause(err: any): this;
setSource(source: any): this;
setData(data: any): this;
setOperational(isOperational: boolean): this;
setHttpStatus(status: number): this;
toJSON(): IException;
private static merge;
static httpStatusByType(type?: ExceptionType): number;
static from(err: any, customParser?: IExceptionParser): Exception;
}