> For the complete documentation index, see [llms.txt](https://webix.gitbook.io/webix-jet/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://webix.gitbook.io/webix-jet/part-ii-webix-jet-in-details/inner-events-and-error-handling.md).

# Inner Events and Error Handling

You can use a number of inner events for some additional actions if the plugins aren't enough or for error handling and debugging.

## Calling Events

You can create custom app-wide events with the callEvent method:

```javascript
// views/top.js
import {JetView} from "webix-jet";
export default class TopView extends JetView {
    config(){
        return {
            view:"icon",
            icon:"wxi-calendar",
            click: () => this.app.callEvent("app:action:calendar", [])
        };
    }
}
```

## Attaching Event Handlers

You can use the [view.on](/webix-jet/part-ii-webix-jet-in-details/inner-events-and-error-handling.md) to handle app events on view level:

```javascript
// views/top.js
import {JetView} from "webix-jet";
export default class TopView extends JetView {
    ...
    init(){
        this.on(this.app, "app:action:remove", id =>
            this.RemoveOption(id)
        );
    }
    RemoveOption(id){
        // remove options
    }
}
```

This way of attaching an event handler is convenient, because it automatically detaches the event handler when the view that called it is destroyed. This helps to avoid memory leaks that may happen, especially in older browsers.

To handle a JetApp event on the app level, call the [app.attachEvent](https://github.com/webix-hub/gitbook-webix-jet/tree/d99cc8000b4a3dddcd04ef5f62f68a1270e6bc6b/part-ii-webix-jet-in-details/api/jetapp-methods.md#app-attachevent) method:

```javascript
// myapp.js
...
// "app:guard" is a default app event
app.attachEvent("app:guard", function(url, view, nav){
    if (url.indexOf("/blocked") !== -1){
        nav.redirect = "/top/allowed";
    }
});
```

[View demo on GitHub >>](https://github.com/webix-hub/jet-demos/blob/master/sources/appguard.js)

![Redirecting users in apps with Webix Jet](https://4168668210-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LBfwSEN2emvHOR268VD%2F-LBfwSscFxB7c2rWD0AY%2F-LBfwgM40gIfpeXPUaZT%2Fappguard.png?generation=1525450734545816\&alt=media)

Go to the [API Reference](https://github.com/webix-hub/gitbook-webix-jet/tree/d99cc8000b4a3dddcd04ef5f62f68a1270e6bc6b/part-ii-webix-jet-in-details/api/jetapp-events.md) to see the full list of default app events.

## Error Handling and Debugging

If you include **webix.js** (not **webix.min.js**) and set the **debug** property in your app config, error messages will be logged in the console. Besides logging errors, this will enable the debugger.

```javascript
// myapp.js
import {JetApp} from "webix-jet";

const app = new JetApp({
    debug: true // console.log and debugger on error
});
```

You can handle error events to avoid a disaster in a production app. For example, if there is something wrong with the app URL that the user tries to access, redirect the app to something valid:

```javascript
// myapp.js
...
app.attachEvent("app:error:resolve", function() {
    webix.delay(() => app.show("/top"));
});
```

All JetApp error events:

* [app:error](https://github.com/webix-hub/gitbook-webix-jet/tree/d99cc8000b4a3dddcd04ef5f62f68a1270e6bc6b/part-ii-webix-jet-in-details/api/jetapp-events.md#app-error) - a common event for all errors.
* [app:error:resolve](https://github.com/webix-hub/gitbook-webix-jet/tree/d99cc8000b4a3dddcd04ef5f62f68a1270e6bc6b/part-ii-webix-jet-in-details/api/jetapp-events.md#app-error-resolve) fires when Jet can't find a module by its name.
* [app:error:render](https://github.com/webix-hub/gitbook-webix-jet/tree/d99cc8000b4a3dddcd04ef5f62f68a1270e6bc6b/part-ii-webix-jet-in-details/api/jetapp-events.md#app-error-render) - the event that is triggered on errors during view rendering, mostly Webix UI related. It means that some view UI config has been written incorrectly.
* [app:error:initview](https://github.com/webix-hub/gitbook-webix-jet/tree/d99cc8000b4a3dddcd04ef5f62f68a1270e6bc6b/part-ii-webix-jet-in-details/api/jetapp-events.md#app-error-initview) - the event that is triggered when there is something wrong with view rendering, mostly Webix Jet related. It means that Jet, while rendering Webix UIs, was unable to render the app UI correctly.

The last two events are mostly helpful for the development stage.
