UNPKG

@btfuse/core

Version:

A native-first framework for building hybdrid web-native applications

88 lines (87 loc) 3.08 kB
import { ISerializable } from "./ISerializable"; import { TFuseSerializable } from "./TSerializable"; /** * A union of acceptable type for error causes. */ export type TFuseErrorCause = string | Error | FuseError | null; interface _IFuseErrorSerialized { domain: string; message: string; code: number; stack?: string; } /** * A type that represents a fuse error in a serialized state. */ export type IFuseErrorSerialized = TFuseSerializable<_IFuseErrorSerialized>; /** * A structured error object. */ export declare class FuseError extends Error implements ISerializable { private $domain; private $message; private $cause; private $code; /** * @param domain - The error domain, usually represents a library, class, or plugin. * @param message - The error message * @param cause - The underlying cause of the error. May be null. * @param code - An error code. May be null. */ constructor(domain: string, message: string, cause?: TFuseErrorCause, code?: number); /** * @returns The error message */ getMessage(): string; /** * @returns The error domain, usually representing a library, class, or plugin. */ getDomain(): string; /** * @returns The error code */ getCode(): number; /** * @returns The underlying cause of the error, if known. May be null. */ getCause(): TFuseErrorCause | null; /** * @returns A serialized object representing an error. */ serialize(): IFuseErrorSerialized; /** * Wraps the given object into a FuseError object. Accepts several different * formats, which influences the behaviour of this method. * * If the input is a string, a FuseError object is created with the string as * the error message of an unknown domain. * * If the input is a FuseError, then this method does nothing but passes through * the FuseError. The returned FuseError is the input FuseError, a copy is not made. * * If the input is an Error, then a FuseError is created using the name as the * domain, and it's message as the error message. The error object is also used * as the FuseError's cause parameter. * * If the input is of the shape of IFuseErrorSerialized, then the object is * deserialized into a FuseError instance. * * If any other type of object is given, an console error message will be * printed and a "FuseError" domain error will be returned stating the error * is not wrappable. * * @param error - A value that can represent an error * @returns A FuseError instance */ static wrap(error: string | Error | FuseError | IFuseErrorSerialized | unknown): FuseError; /** * Deserializes and creates a new FuseError instance * * @param error - The serialized error object * @returns A FuseError instance */ static fromSerialized(error: IFuseErrorSerialized): FuseError; toString(): string; private static $isSerializedFuseError; } export {};