Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ add global error handler #256

Merged
merged 2 commits into from Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 38 additions & 0 deletions docs/api/README.md
Expand Up @@ -137,3 +137,41 @@

runAfterFirstMounted(() => startMonitor());
```

## [addErrorHandler/removeErrorHandler](https://single-spa.js.org/docs/api#adderrorhandler)

## `addGlobalUncaughtErrorHandler(handler)`

- Parameters

- handler - `(...args: any[]) => void` - 必选

- Usage

Add the global uncaught error hander.

- Sample

```ts
import { addGlobalUncaughtErrorHandler } from 'qiankun';

addGlobalUncaughtErrorHandler(event => console.log(event));
```

## `removeGlobalUncaughtErrorHandler(handler)`

- Parameters

- handler - `(...args: any[]) => void` - 必选

- Usage

Remove the global uncaught error hander.

- Sample

```ts
import { removeGlobalUncaughtErrorHandler } from 'qiankun';

removeGlobalUncaughtErrorHandler(handler);
```
39 changes: 39 additions & 0 deletions docs/zh/api/README.md
Expand Up @@ -137,3 +137,42 @@

runAfterFirstMounted(() => startMonitor());
```

## [addErrorHandler/removeErrorHandler](https://single-spa.js.org/docs/api#adderrorhandler)

## `addGlobalUncaughtErrorHandler(handler)`

- 参数

- handler - `(...args: any[]) => void` - 必选

- 用法

添加全局的未捕获异常处理器。

- 示例

```ts
import { addGlobalUncaughtErrorHandler } from 'qiankun';

addGlobalUncaughtErrorHandler(event => console.log(event));
```

## `removeGlobalUncaughtErrorHandler(handler)`

- 参数

- handler - `(...args: any[]) => void` - 必选

- 用法

移除全局的未捕获异常处理器。

- 示例

```ts
import { removeGlobalUncaughtErrorHandler } from 'qiankun';

removeGlobalUncaughtErrorHandler(handler);
```

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -53,7 +53,7 @@
"@babel/runtime": "^7.5.5",
"import-html-entry": "^1.3.9",
"lodash": "^4.17.11",
"single-spa": "^4.3.4",
"single-spa": "^4.4.3",
"tslib": "^1.10.0"
},
"devDependencies": {
Expand Down
16 changes: 16 additions & 0 deletions src/errorHandler.ts
@@ -0,0 +1,16 @@
/**
* @author Kuitos
* @since 2020-02-21
*/

export { addErrorHandler, removeErrorHandler } from 'single-spa';

export function addGlobalUncaughtErrorHandler(errorHandler: OnErrorEventHandlerNonNull): void {
window.addEventListener('error', errorHandler);
window.addEventListener('unhandledrejection', errorHandler);
}

export function removeGlobalUncaughtErrorHandler(errorHandler: (...args: any[]) => any) {
window.removeEventListener('error', errorHandler);
Deturium marked this conversation as resolved.
Show resolved Hide resolved
window.removeEventListener('unhandledrejection', errorHandler);
}
1 change: 1 addition & 0 deletions src/index.ts
Expand Up @@ -4,5 +4,6 @@
*/

export * from './register';
export * from './errorHandler';
export * from './effects';
export * from './interfaces';