UNPKG

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

34 lines (33 loc) 935 B
/** * Error Code Wrapper * When an error code is inserted into a message (encoding a message), it must be wrapped first so * it can be decoded later. */ type IErrorCodeWrapper = { prefix: string; suffix: string; }; /** * Error Code * The code that is inserted when encoding an error. If none is provided or none can be extracted, * it defaults to -1. */ type IErrorCode = string | number; /** * Unwrapped Error Code * In order to decode an error, the code must be first unwrapped. */ type IUnwrappedErrorCode = { code: IErrorCode; startsAt: number; }; /** * Decoded Error * The object obtained when an error is decoded. Keep in mind that if the error message or the code * cannot be extracted for any reason, the default values will be set instead. */ type IDecodedError = { message: string; code: IErrorCode; }; export type { IErrorCodeWrapper, IErrorCode, IUnwrappedErrorCode, IDecodedError };