error-message-utils
Version:
The error-message-utils package simplifies error management in your web applications and RESTful APIs. It ensures consistent and scalable handling of error messages, saving you time and effort. Moreover, it gives you the ability to assign custom error cod
37 lines (36 loc) • 1.36 kB
TypeScript
import { IErrorCode, IDecodedError } from './shared/types.js';
/**
* Attempts to extract an error message from an error that could be anything. If it fails to do so,
* it returns the default message.
* @param error
* @returns string
*/
declare const extractMessage: (error: any) => string;
/**
* Verifies if a value matches the default error message used by this package.
* @param value
* @param fullMatch?
* @returns boolean
*/
declare const isDefaultErrorMessage: (value: string, fullMatch?: boolean) => value is string;
/**
* Given an error in any format, it extracts the message and inserts the code at the end.
* @param error
* @param code
* @returns string
*/
declare const encodeError: (error: any, code: IErrorCode) => string;
/**
* Given an error, it will extract the encoded message and attempt to decode it. If successful,
* it separates the error message from the code so it can be shown directly to the user.
* @param error
* @returns IDecodedError
*/
declare const decodeError: (error: any) => IDecodedError;
/**
* Determines if a given error (in any format) is an error encoded by this package.
* @param error
* @returns boolean
*/
declare const isEncodedError: (error: any) => boolean;
export { type IErrorCode, type IDecodedError, extractMessage, isDefaultErrorMessage, encodeError, decodeError, isEncodedError, };