Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
react-native-exception-handler
Advanced tools
A react native module that lets you to register a global error handler that can capture fatal/non fatal uncaught exceptions.
A react native module that lets you to register a global error handler that can capture fatal/non fatal uncaught exceptions. The module helps prevent abrupt crashing of RN Apps without a graceful message to the user.
In the current scenario:
In DEV mode , you get a RED Screen error pointing your JS errors.
In Bundled mode , the app just quits without any prompt !
🙄To tackle this we register a global error handler that could be used to for example:
yarn add react-native-exception-handler¸
or
npm i react-native-exception-handler --save
import {setJSExceptionHandler} from 'react-native-exception-handler';
.
.
.
const errorHandler = (error, isFatal) => {
// This is your custom global error handler
}
.
.
.
setJSExceptionHandler(errorHandler); // registering the error handler (maybe u can do this in the index.android.js or index.ios.js)
or
setJSExceptionHandler(errorHandler, true); //Second argument true is basically
//if u need the handler to be called in place of RED
//screen in development mode also
In DEV MODE
In BUNDLED MODE
With Error handling in BUNDLED MODE
This example shows how to use this module show a graceful bug dialog to the user on crash and restart the app when the user presses ok !
import {Alert} from 'react-native';
import RNRestart from 'react-native-restart';
import {setJSExceptionHandler} from 'react-native-exception-handler';
const errorHandler = (e, isFatal) => {
if (isFatal) {
Alert.alert(
'Unexpected error occurred',
`
Error: ${(isFatal) ? 'Fatal:' : ''} ${e.name} ${e.message}
We will need to restart the app.
`,
[{
text: 'Restart',
onPress: () => {
RNRestart.Restart();
}
}]
);
} else {
console.log(e); // So that we can see it in the ADB logs in case of Android if needed
}
};
setJSExceptionHandler(errorHandler);
This example shows how to use this module to send global errors to the dev team and show a graceful bug dialog to the user on crash !
import {Alert} from 'react-native';
import {BackAndroid} from 'react-native';
import {setJSExceptionHandler} from 'react-native-exception-handler';
const reporter = (error) => {
// Logic for reporting to devs
// Example : Log issues to github issues using github apis.
console.log(error); // sample
};
const errorHandler = (e, isFatal) => {
if (isFatal) {
reporter(e);
Alert.alert(
'Unexpected error occurred',
`
Error: ${(isFatal) ? 'Fatal:' : ''} ${e.name} ${e.message}
We have reported this to our team ! Please close the app and start again!
`,
[{
text: 'Close',
onPress: () => {
BackAndroid.exitApp();
}
}]
);
} else {
console.log(e); // So that we can see it in the ADB logs in case of Android if needed
}
};
setJSExceptionHandler(errorHandler);
More Examples can be found in the examples folder
FAQs
A react native module that lets you to register a global error handler that can capture fatal/non fatal uncaught exceptions.
The npm package react-native-exception-handler receives a total of 39,507 weekly downloads. As such, react-native-exception-handler popularity was classified as popular.
We found that react-native-exception-handler demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.