@mdf.js/crash
Version:
MMS - API Crash - Enhanced error management library
88 lines • 3.44 kB
TypeScript
/**
* Copyright 2024 Mytra Control S.L. All rights reserved.
*
* Use of this source code is governed by an MIT-style license that can be found in the LICENSE file
* or at https://opensource.org/licenses/MIT.
*/
import { Base } from '../BaseError';
import { Multi } from '../Multi';
import { Cause, CrashObject, CrashOptions } from '../types';
/**
* Improved handling of standard errors.
*
* Crash helps us manage standard errors within our application by providing us with some tools:
* - Association of errors and their causes in a hierarchical way.
* - Simple search for root causes within the hierarchy of errors.
* - Stack management, both of the current instance of the error, and of the causes.
* - Facilitate error logging.
*
* In addition, in combination with the Multi error types, errors in validation processes, and Boom,
* errors for the REST-API interfaces, it allows a complete management of the different types of
* errors in our backend.
* @category Crash
* @public
*/
export declare class Crash extends Base {
/** Crash error cause */
private readonly _cause?;
/** Crash error */
private readonly _isCrash;
/**
* Check if an object is a valid Crash or Multi error
* @param error - error to be checked
* @param uuid - Optional uuid to be used instead of a random one.
* @returns
*/
static from(error: unknown, uuid?: string): Multi | Crash;
/**
* Create a new Crash error instance
* @param message - human friendly error message
*/
constructor(message: string);
/**
* Create a new Crash error
* @param message - human friendly error message
* @param options - enhanced error options
*/
constructor(message: string, options: CrashOptions);
/**
* Create a new Crash error
* @param message - human friendly error message
* @param uuid - unique identifier for this particular occurrence of the problem
*/
constructor(message: string, uuid: string);
/**
* Create a new Crash error
* @param message - human friendly error message
* @param uuid - unique identifier for this particular occurrence of the problem
* @param options - enhanced error options
*/
constructor(message: string, uuid: string, options: CrashOptions);
/** Determine if this instance is a Crash error */
get isCrash(): boolean;
/** Cause source of error */
get cause(): Cause | undefined;
/** Get the trace of this hierarchy of errors */
trace(): string[];
/**
* Look in the nested causes of the error and return the first occurrence of a cause with the
* indicated name
* @param name - name of the error to search for
* @returns the cause, if there is any present with that name
*/
findCauseByName(name: string): Cause | undefined;
/**
* Check if there is any cause in the stack with the indicated name
* @param name - name of the error to search for
* @returns Boolean value as the result of the search
*/
hasCauseWithName(name: string): boolean;
/**
* Returns a full stack of the error and causes hierarchically. The string contains the
* description of the point in the code at which the Error/Crash was instantiated
*/
fullStack(): string | undefined;
/** Return Crash error in JSON format */
toJSON(): CrashObject;
}
//# sourceMappingURL=CrashError.d.ts.map