Skip to content

Commit 2e9a184

Browse files
committed
Merge branch 'get-handler'
2 parents 56aa62c + 767ff2e commit 2e9a184

File tree

6 files changed

+851
-8
lines changed

6 files changed

+851
-8
lines changed

.eslintrc

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
"react",
1111
"react-native"
1212
],
13-
"ecmaFeatures": {
14-
"jsx": true
13+
"parserOptions": {
14+
"ecmaFeatures": {
15+
"jsx": true
16+
},
17+
"sourceType": "module"
1518
},
1619
"extends": ["eslint:recommended", "plugin:react/recommended"],
1720
"rules": {

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ npm i react-native-exception-handler --save
2727
### Usage
2828

2929
```js
30-
import {setJSExceptionHandler} from 'react-native-exception-handler';
30+
import {setJSExceptionHandler, getJSExceptionHandler} from 'react-native-exception-handler';
3131

3232
.
3333
.
@@ -48,6 +48,8 @@ or
4848
setJSExceptionHandler(errorHandler, true); //Second argument true is basically
4949
//if u need the handler to be called in place of RED
5050
//screen in development mode also
51+
52+
const currentHandler = getJSExceptionHandler(); // getJSExceptionHandler gives the currently set handler
5153
```
5254

5355

@@ -158,6 +160,7 @@ setJSExceptionHandler(errorHandler);
158160
```
159161

160162
*More Examples can be found in the examples folder*
163+
- Preserving old handler
161164

162165
## NOTES
163166
1. This module only helps in catching the runtime errors in JS. Native errors can still crash your app without any prompt.

examples/preservingOldHandler.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {getJSExceptionHandler, setJSExceptionHandler} from 'react-native-exception-handler';
2+
3+
const customErrorHandler = (error, isFatal) => {
4+
// Logic for reporting to devs
5+
// Example : Log issues to github issues using github apis.
6+
console.log(error, isFatal); // example
7+
};
8+
9+
const previousErrorHandler = getJSExceptionHandler(); // by default u will get the red screen error handler here
10+
11+
const errorHandler = (e, isFatal) => {
12+
customErrorHandler(e, isFatal);
13+
previousErrorHandler(e, isFatal);
14+
};
15+
16+
// We will still see the error screen, but our customErrorHandler() function will be called
17+
setJSExceptionHandler(errorHandler);

index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ export const setJSExceptionHandler = (customHandler = noop, allowedInDevMode = f
99
}
1010
};
1111

12+
export const getJSExceptionHandler = () => global.ErrorUtils.getGlobalHandler();
13+
1214
export default {
13-
setJSExceptionHandler
15+
setJSExceptionHandler,
16+
getJSExceptionHandler
1417
};

package.json

+10-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"description": "A react native module that lets you to register a global error handler that can capture fatal/non fatal uncaught exceptions.",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo no tests && exit 1",
8-
"lint": "eslint app/",
9-
"lint:fix": "eslint app/ --fix"
7+
"test": "echo no tests && exit 1",
8+
"lint": "eslint app/",
9+
"lint:fix": "eslint app/ --fix"
1010
},
1111
"repository": {
1212
"type": "git",
@@ -35,5 +35,11 @@
3535
"bugs": {
3636
"url": "https://github.com/master-atul/react-native-exception-handler/issues"
3737
},
38-
"homepage": "https://atulr.com/react-native-exception-handler"
38+
"homepage": "https://github.com/master-atul/react-native-exception-handler",
39+
"devDependencies": {
40+
"babel-eslint": "^7.2.3",
41+
"eslint": "^4.0.0",
42+
"eslint-plugin-react": "^7.1.0",
43+
"eslint-plugin-react-native": "^2.3.2"
44+
}
3945
}

0 commit comments

Comments
 (0)