Skip to content

Commit

Permalink
Update usage samples doc with sample of subscribing error event (#164)
Browse files Browse the repository at this point in the history
* Update usage samples doc with sample of subscribing error event

* Update events.md

* update notes to usage sample error handling
  • Loading branch information
zaheral authored Apr 18, 2024
1 parent 0a7f8dd commit c142078
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/events.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# API Documentation

If this is your first time using the Shell-SDK, then we recommend to have a look on our [usage samples](./usage-sample.md).

## Events

- ### REQUIRE_CONTEXT
Expand Down
31 changes: 31 additions & 0 deletions docs/usage-sample.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,37 @@
Shell->>Application: SHELL_EVENTS.Version1.REQUIRE_CONTEXT
```

- ## Subscribing to errors coming from shell host application

We highly recommend to include this event to your application, because it is the main way to catch errors communicated from the Shell.

```typescript
shellSdk.emit(SHELL_EVENTS.Version1.REQUIRE_CONTEXT, {
clientIdentifier: '<your-app-client-identifier>',
clientSecret: '<your-app-client-secret>',
});

shellSdk.on(SHELL_EVENTS.Version1.REQUIRE_CONTEXT, handler);
shellSdk.on(SHELL_EVENTS.ERROR, errorhandler);

const handler = (context, origin) => {
// Will be not triggered in case of an error
};

const errorhandler = (error) => {
// Error with information of the failed event sent to Shell
};
```

A proper error handling should include :

- User notification that an error happened.
- Wait time before the same event (error causing) is send again to Shell.
- Limit amount of retry. When the same error happens again and again, don't continue to call the event in an infinity loop.

Missing proper error handling can result in too many (misuse) API calls.
In worst case such a violation can result in deactivation of the extension.

- ## Unsubscribing from event

to unsibscribe use _off_ method from _ShellSdk_
Expand Down

0 comments on commit c142078

Please sign in to comment.