Error manager that handles the application's errors and the user's history.

If the app crashes, the errors and history will be exported to a zip file. The zip file will be encrypted with a password. The password is 123456789.

This means that you, as a developer, can read the errors and history of the user. No more guessing or vague descriptions of the error.

You can only read the errors and history of the user if the user sends you the zip file. The zip file will be saved in the downloads folder of the user's device. The zip file will be named MyErrorReport_<date>.errorReport.

No data will be sent to any server. You need to add that yourself :)

Hierarchy

  • EventDispatcher
    • ErrorManager

Implements

  • AbstractErrorManager

Methods

  • Adds the specified event listener.

    Parameters

    • type: string

      event name

    • listener: Listener

      handler function

    Returns void

  • Fire an event type.

    Parameters

    • event: DispatcherEvent

      DispatcherEvent

    Returns void

  • Presence of the specified event listener.

    Parameters

    • type: string

      event name

    • listener: Listener

      handler function

    Returns boolean

  • Removes all event listeners

    Parameters

    • Optional type: string

      event name

    Returns void

  • Removes the specified event listener

    Parameters

    • type: string

      event name

    • listener: Listener

      handler function

    Returns void

Other

  • Constructs an instance of the ErrorManager class.

    Parameters

    • Optional attemptClear: boolean = true

      Indicates whether to attempt to clear errors asynchronously upon initialization.

    • Optional store: LocalForage

      An optional store instance created by the createInstance function.

    Returns ErrorManager

    Example

    const errorManager = new ErrorManager(true,
    createInstance({ name: ErrorManager.STORE_NAME, driver: INDEXEDDB })
    );
_errors: AbstractErrorObject[]

Errors that have been thrown.

_history: AbstractHistoryObject[]

Log of all actions that have been performed.

_store?: LocalForage

A private property that optionally holds the return type of the createInstance function. This property is used to store an instance created by the createInstance function.

DEBUG: boolean = true

A flag indicating whether debug mode is enabled. When set to true, additional debug information may be logged. This can be useful for development and troubleshooting purposes.

FILE_EXTENSION: "errorReport" = ...

The file extension used for error reports. This is a constant value set to 'errorReport'.

FILE_PREFIX: "MyErrorReport" = ...

A constant string that serves as the prefix for error report files. This prefix is used to name the error report files generated by the ErrorManager.

PASSWORD: "123456789" = ...
STORE_KEY: "errors" = ...
STORE_NAME: "errorStore" = ...
_instance: ErrorManager

ErrorManager singleton

  • Converts the internal errors array to an exportable object. Each error is keyed by its timestamp in ISO string format.

    Returns ExportObject

    An object where each key is an error's timestamp in ISO string format and each value is the error serialized to JSON.

  • Converts the internal history array to an exportable object. Each entry in the history is keyed by its timestamp in ISO string format.

    Returns ExportObject

    An object where each key is a timestamp and each value is the corresponding history entry in JSON format.

  • Private

    Downloads a file using the provided Blob object and file name.

    Parameters

    • blob: Blob

      The Blob object representing the file to be downloaded.

    • fileName: string

      The name to be given to the downloaded file.

    Returns void

  • Generates a file name based on the current date and time.

    If the DEBUG flag is set to true, it returns 'debug.zip'. Otherwise, it generates a file name using the current date and time, replacing all non-alphanumeric characters with underscores.

    Returns string

    The generated file name.

  • Retrieves the user information.

    Returns {
        browserEngine: string;
        browserLanguage: string;
        browserName: string;
        browserOnline: boolean;
        browserPlatform: string;
        browserVersion1a: string;
        browserVersion1b: string;
        dataCookies1: string;
        dataCookies2: string;
        dataCookiesEnabled: boolean;
        dataStorage: Storage;
        javaEnabled: boolean;
        pageOn: string;
        previousSites: number;
        referrer: string;
        scrColorDepth: number;
        scrPixelDepth: number;
        sizeAvailH: number;
        sizeAvailW: number;
        sizeDocH: any;
        sizeDocW: any;
        sizeInH: number;
        sizeInW: number;
        sizeScreenH: number;
        sizeScreenW: number;
        timeOpened: Date;
        timezone: number;
        zoomLevel: undefined | number;
    }

    The user object.

    • Readonly browserEngine: string
    • Readonly browserLanguage: string
    • Readonly browserName: string
    • Readonly browserOnline: boolean
    • Readonly browserPlatform: string
    • Readonly browserVersion1a: string
    • Readonly browserVersion1b: string
    • Readonly dataCookies1: string
    • Readonly dataCookies2: string
    • Readonly dataCookiesEnabled: boolean
    • Readonly dataStorage: Storage
    • Readonly javaEnabled: boolean
    • Readonly pageOn: string
    • Readonly previousSites: number
    • Readonly referrer: string
    • Readonly scrColorDepth: number
    • Readonly scrPixelDepth: number
    • Readonly sizeAvailH: number
    • Readonly sizeAvailW: number
    • Readonly sizeDocH: any
    • Readonly sizeDocW: any
    • Readonly sizeInH: number
    • Readonly sizeInW: number
    • Readonly sizeScreenH: number
    • Readonly sizeScreenW: number
    • Readonly timeOpened: Date
    • Readonly timezone: number
    • Readonly zoomLevel: undefined | number
  • Private

    Generates a ZIP file blob containing the user's history, errors, and user information.

    Returns Promise<Blob>

    A promise that resolves to a Blob representing the ZIP file.

    Async

    Remarks

    • If ErrorManager.DEBUG is true, the ZIP file will not be encrypted.
    • If ErrorManager.DEBUG is false, the ZIP file will be encrypted with the password specified in ErrorManager.PASSWORD and an encryption strength of 1.

    Throws

    If there is an issue creating or adding files to the ZIP.

  • Private

    Saves the current state of errors and history to the store asynchronously.

    Returns Promise<void>

    A promise that resolves when the state has been saved.

    Throws

    If the store is not defined.

  • Adds a history object to the history list, saves the history asynchronously, and dispatches a history event.

    Parameters

    • _history: AbstractHistoryObject

      The history object to be added. Must implement the AbstractHistoryObject interface.

    Returns Promise<void>

    A promise that resolves when the history object has been added and saved.

    Throws

    If the provided object is not a valid history object.

  • Attempts to clear the errors and history asynchronously.

    Returns Promise<boolean>

    A promise that resolves to true if the errors and history were cleared, or false if they were loaded from the store.

    Throws

    If the store is not defined.

    The method performs the following steps:

    1. Checks if the store is defined. If not, throws an error.
    2. Determines if the errors and history should be cleared by calling shouldClear.
    3. If they should be cleared, calls clear and returns true.
    4. If not, attempts to load the errors and history from the store.
    5. If loading from the store fails, clears the errors and history and returns true.
    6. If loading from the store succeeds, sets the errors and history to the loaded values and returns false.
  • Clears the current errors and history from the error manager.

    This method will reset the _errors and _history arrays to empty arrays. It will then update the store with the cleared state.

    Returns Promise<void>

    A promise that resolves when the store has been updated.

    Throws

    If the store is not defined.

  • Handles an error by performing several actions:

    1. Validates if the provided object is an error object.
    2. Adds the error object to the internal errors list.
    3. Asynchronously saves the error.
    4. Dispatches an error event.

    Parameters

    • _error: AbstractErrorObject

      The error object to handle. Must be an instance of AbstractErrorObject.

    Returns Promise<Error>

    A promise that resolves to an Error indicating the method is not fully implemented.

    Throws

    Will throw an error if the provided object is not a valid error object.

  • Exports the error data as a ZIP file.

    Parameters

    • Optional downloadFile: boolean = true

      Whether to download the file after exporting.

    Returns Promise<{
        blob: Blob;
        fileName: string;
    }>

    A promise that resolves with the file name and the Blob object of the ZIP file.

    Fires

    EVENT_TYPES.EXPORT_BEGIN - Dispatched when the export process begins.

    Fires

    EVENT_TYPES.EXPORT_DONE - Dispatched when the export process is completed.

  • Retrieves the list of errors.

    Returns readonly AbstractErrorObject[]

    A read-only array of error objects.

  • Retrieves the history of error objects.

    Returns readonly AbstractHistoryObject[]

    An array of history objects that is read-only.

  • Determine if the errors and history should be cleared. Override this method to change the behavior.

    Returns Promise<boolean>

    true if the errors and history were cleared.