Displaying Errors & Notifications

Sometimes things go awry and TextSync will want to display an error message or notification to your users. For example, if the editor cannot recover its connection to the server you'll want your users to know what is happening.

By default, we will display a dismissable notification in the top right-hand corner of the screen:

sample-editor

However, if you'd rather handle displaying these messages yourself this guide is for you.

Disable Default Notifications

You can disable the default notifications by setting theshowNotifications flag to false when instantiating the editor:

1
2
3
4
textSyncInstance.createEditor({
  /* ...other params... */
  errorNotifications: false
});

Register a Notification Callback

You can register a callback to receive notification data from TextSync by passing a reference to the callback into the createEditor function:

1
2
3
4
5
6
7
8
9
textSyncInstance.createEditor({
  /* ...other params... */
  onError: (notification) => {
    console.log(
      "There was an error of type " + notification.notificationType +
      " and with message " + notification.message
    );
  }
});

Notification Callback

When a notification-worthy event occurs, the onError callback will be invoked with a single argument containing a notification object.

Example

1
2
3
4
{
  notificationType: 'warning',
  message: 'The network connection has been lost. Reconnecting...'
}

Notification Types

When the callback is fired we will provide you with a notificationType along with a human readablemessage string. This can be used to change how you render the notifications to indicate severity to your users. These types are as follows:

  • info: Nothing bad has happened but the user needs to be made aware of something.

  • warning: Something bad has happened but TextSync is going to make an attempt to recover.

  • error: Something really bad has happened and TextSync cannot recover.

Notes

errorNotifications flag and onError callback are independent of one another. This means that you can use our notifications, yours, both or neither - it's your choice.

Did you find this document useful?

We are always striving to create the most accurate and informative docs as possible. If there is something especially wrong (or right) here then please let us know.