UNPKG

@mdf.js/crash

Version:

MMS - API Crash - Enhanced error management library

109 lines 4.2 kB
/** * 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 { Cause } from '..'; import { Base } from '../BaseError'; import type { MultiObject, MultiOptions, ValidationError } from '../types'; /** * Improved handling of validation errors. * * Multi helps us to manage validation or information transformation errors, in other words, it * helps us manage any process that may generate multiple non-hierarchical errors (an error is not a * direct consequence of the previous one) by providing us with some tools: * - Management of the error stack. * - Simple search for root causes within the error stack. * - Stack management, both of the current instance of the error, and of the causes. * - Facilitate error logging. * * Furthermore, in combination with the types of error Boom, errors for the REST-API interfaces, and * Crash, standard application errors, it allows a complete management of the different types of * errors in our backend. * @category Multi * @public */ export declare class Multi extends Base { /** Multi error causes */ private _causes?; /** Multi error */ private readonly _isMulti; /** * Create a new Multi error * @param message - human friendly error message */ constructor(message: string); /** * Create a new Multi error * @param message - human friendly error message * @param options - enhanced error options */ constructor(message: string, options: MultiOptions); /** * Create a new Multi 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 Multi 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: MultiOptions); /** * Extract the causes from the options * @param uuid - unique identifier for this particular occurrence of the problem * enhanced error options * @param options - enhanced error options * @returns */ private extractCauses; /** Determine if this instance is a Multi error */ get isMulti(): boolean; /** Causes source of error */ get causes(): Cause[] | undefined; /** Return the number of causes of this error */ get size(): number; /** 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/Multi was instantiated */ fullStack(): string | undefined; /** * Add a new error on the array of causes * @param error - Cause to be added to the array of causes */ push(error: Cause): void; /** * Remove a error from the array of causes * @returns the cause that have been removed */ pop(): Cause | undefined; /** Return Multi error in JSON format */ toJSON(): MultiObject; /** * Process the errors thrown by Joi into the cause array * @param error - `ValidationError` from a Joi validation process * @returns number or error that have been introduced */ Multify(error: ValidationError): number; } //# sourceMappingURL=MultiError.d.ts.map