@mdf.js/crash
Version:
MMS - API Crash - Enhanced error management library
98 lines • 3.78 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 { Cause } from '..';
import { Base } from '../BaseError';
import { APIError, APISource, BoomOptions, Links, ValidationError } from '../types';
/**
* Improved error handling in REST-API interfaces
*
*
* Boom helps us with error responses (HTTP Codes 3XX-5XX) within our REST-API interface by
* providing us with some tools:
* - Helpers for the rapid generation of standard responses.
* - Association of errors and their causes in a hierarchical way.
* - Adaptation of validation errors of the Joi library.
*
* In addition, in combination with the Multi error types, errors in validation processes, and
* Crash, standard application errors, it allows a complete management of the different types of
* errors in our backend.
* @category Boom
* @public
*/
export declare class Boom extends Base {
/** Boom error cause */
private _cause?;
/** Boom error code */
private readonly _code;
/** Links that leads to further details about this particular occurrence of the problem */
private readonly _links?;
/** An object containing references to the source of the error */
private readonly _source?;
/** Boom error */
private readonly _isBoom;
/**
* Create a new Boom error
* @param message - human friendly error message
* @param uuid - unique identifier for this particular occurrence of the problem
* @param code - HTTP Standard error code
* @param options - enhanced error options
*/
constructor(message: string, uuid: string, code?: number, options?: BoomOptions);
/** Return APIError in JSON format */
toJSON(): APIError;
/** Boom error code */
get status(): number;
/**
* Links that leads to further details about this particular occurrence of the problem.
* A link MUST be represented as either:
* - self: a string containing the link’s URL
* - related: an object (“link object”) which can contain the following members:
* - href: a string containing the link’s URL.
* - meta: a meta object containing non-standard meta-information about the link.
*/
get links(): Links | undefined;
/**
* Object with the key information of the requested resource in the REST API context
* @deprecated - `source` has been deprecated, use resource instead
*/
get source(): APISource | undefined;
/** Object with the key information of the requested resource in the REST API context */
get resource(): APISource | undefined;
/** Boom error */
get isBoom(): boolean;
/** Cause source of error */
get cause(): Cause | undefined;
/** Get the trace of this hierarchy of errors */
trace(): string[];
/**
* Transform joi Validation error in a Boom error
* @param error - `ValidationError` from a Joi validation process
*/
Boomify(error: ValidationError): void;
/**
* Check if the cause are type safe and valid
* @param uuid - unique identifier for this particular occurrence of the problem
* @param cause - Crash error cause
*/
private typeSafeCause;
/**
* Check if links are type safe and valid
* @param links - Information links for error
*/
private typeSafeLinks;
/**
* Check if links are type safe and valid
* @param links - Information links for error
*/
private typeSafeContextLinks;
/**
* Check if source are type safe and valid
* @param source - Source of error
*/
private typeSafeSource;
}
//# sourceMappingURL=BoomError.d.ts.map