LogoPixi’VN
indexNamespacesGameFunctions

Function: addOnError()

> addOnError(value): () => void

Defined in: src/index.ts:363

Register an error handler. Multiple handlers can be registered; they will be executed in registration order.

You can also check if the error is an instance of PixiError to handle specific errors related to Pixi’VN.

Parameters

value

OnErrorHandler

Returns

() => void

Example

// Register a synchronous error handler
Game.addOnError((error, props) => {
   props.notify("An error occurred")
   // send a notification to GlitchTip, Sentry, etc...
})

// Register an error handler for Pixi’VN specific errors
Game.addOnError((error, { notify }) => {
    if (error instanceof PixiError) {
        // ...
    }
});

// Register an asynchronous error handler
Game.addOnError(async (error, props) => {
   await logErrorToServer(error)
   props.notify("An error occurred")
})

// Register an error handler with step restoration/rollback
Game.addOnError(async (error, props) => {
   // Restore the game state to the previous step
   await stepHistory.back(props)
   props.notify("An error occurred, returning to previous step")
})