import ExtendableError from 'es6-error'; import { ConvertedType, ConvertFn, DeserializeOpts, IBaseError, IBaseErrorConfig, SerializedError, SerializedErrorSafe } from '../interfaces'; /** * Improved error class. */ export declare class BaseError extends ExtendableError implements IBaseError { protected _errId: string; protected _reqId: string; protected _type: string; protected _code: string | number; protected _subCode: string | number; protected _statusCode: any; protected _causedBy: any; protected _safeMetadata: Record; protected _metadata: Record; protected _logLevel: string | number; protected _config: IBaseErrorConfig; protected _hasMetadata: boolean; protected _hasSafeMetadata: boolean; protected _onConvert: ConvertFn | null; protected _appendedWithErrorMsg: boolean; constructor(message: string, config?: IBaseErrorConfig); /** * Assign a log level to the error. Useful if you want to * determine which log level to use when logging the error. * @param {string|number} logLevel */ withLogLevel(logLevel: string | number): this; /** * Set an error id used to link back to the specific error * @param errId */ withErrorId(errId: string): this; /** * Set a request id used to link back to the specific error * @param requestId */ withRequestId(requestId: string): this; /** * Set the error type * @param type */ withErrorType(type: string): this; /** * Set high level error code * @param code */ withErrorCode(code: string | number): this; /** * Set low level error code * @param subCode */ withErrorSubCode(subCode: string | number): this; /** * Gets the log level assigned to the error */ getLogLevel(): string | number; /** * Get the instance-specific error id */ getErrorId(): string; /** * Get the request id associated with the error */ getRequestId(): string; /** * Get the class name of the error */ getErrorName(): string; /** * Get the low level error type */ getErrorType(): string; /** * Returns the status code. */ getStatusCode(): any; /** * Returns the high level error code */ getCode(): string | number; /** * Returns the low level error code */ getSubCode(): string | number; /** * Returns the attached error */ getCausedBy(): any; /** * Returns metadata set by withMetadata() */ getMetadata(): Record; /** * Returns metadata set by withSafeMetadata() */ getSafeMetadata(): Record; /** * Gets the error config */ getConfig(): IBaseErrorConfig; /** * Sets the error config */ setConfig(config: IBaseErrorConfig): this; /** * Replaces sprintf() flags in an error message, if present. * @see https://www.npmjs.com/package/sprintf-js * @param args */ formatMessage(...args: any[]): this; /** * Attach the original error that was thrown, if available * @param {Error} error */ causedBy(error: any): this; /** * Appends the caused by message to the main error message if * the appendWithErrorMessageFormat config item is defined. */ protected appendCausedByMessage(): void; /** * Adds metadata that will be included with toJSON() serialization. * Multiple calls will append and not replace. * @param {Object} metadata */ withMetadata(metadata: Record): this; /** * Set a protocol-specific status code * @param statusCode */ withStatusCode(statusCode: any): this; /** * Adds metadata that will be included with toJSON() / toJsonSafe() * serialization. Multiple calls will append and not replace. * @param {Object} metadata */ withSafeMetadata(metadata: Record): this; /** * Returns a json representation of the error. Assume the data * contained is for internal purposes only as it contains the stack trace. * Use / implement toJsonSafe() to return data that is safe for client * consumption. * @param {string[]} [fieldsToOmit] An array of root properties to omit from the output */ toJSON(fieldsToOmit?: string[]): Partial; /** * Returns a safe json representation of the error (error stack / causedBy is removed). * This should be used for display to a user / pass to a client. * @param {string[]} [fieldsToOmit] An array of root properties to omit from the output */ toJSONSafe(fieldsToOmit?: string[]): Partial; /** * Calls the user-defined `onConvert` function to convert the error into another type. * If `onConvert` is not defined, then returns the error itself. */ convert(): T; /** * Returns true if the onConvert handler is defined */ hasOnConvertDefined(): boolean; /** * Set the onConvert handler for convert() calls. * This can also be defined via the onConvert config property in the constructor. */ setOnConvert(convertFn: ConvertFn): void; /** * Helper method for use with fromJson() * @param errInstance An error instance that extends BaseError * @param {string} data JSON.parse()'d error object from * BaseError#toJSON() or BaseError#toJSONSafe() * @param {DeserializeOpts} [opts] Deserialization options */ static copyDeserializationData(errInstance: T, data: Partial, opts: U): void; /** * Deserializes an error into an instance * @param {string} data JSON.parse()'d error object from * BaseError#toJSON() or BaseError#toJSONSafe() * @param {DeserializeOpts} [opts] Deserialization options */ static fromJSON(data: Partial, opts?: T): IBaseError; }