mattermost-mobile/app/utils/error_handling.js
Chris Duarte e8712f9199 Cold startup js refactor (#1598)
* Switch to SingleDex and remove all locales

* WIP Mattermost Start Component for lazy loading modules

* Add files changed for native modules

* Add Entry component and app global object

* dispatch setStatusBarHeight for iOS

* Update screen imports

* Include Entry screen

* Refactor app to mattermost.android.js

* Override unnecessary java files

* Fix minor issues in changes

* Display empty state based on user credentials

Also, add proper background theme for empty loading screen

* Add native module constant cache support

* Fix startup theme regression

* Add Keychain support for credentials

* Fix Orientation regression

*  Fix SharedExtension regression

* Emit NATIVE_APP_LAUNCHED across bridge only once during cold start

* Add iOS Support

* Revert to previous implementation of i18n

* Fix styling issues

* Include listener for SERVER_VERSION_CHANGED

* Add SafeAreaView in Entry screen

* Register deviceToken early, in order to get iOS PN Support

* Include StartTimeModule

* Add ReplyFromPush support and remove NATIVE_APP_LAUNCHED listener

* Package native constants in StartTimeModule and avoid bridge calls

* Fix check-style errors

* Code cleanup

* Rename StartTimeModule to InitializationModule

* Remove NavigationApplication

* Documentation and minor changes

* Account for app opening after SharedExtension

* Refactor getIntl to getTranslations

* Move native module constants into it's own forked repos

* Include FetchBlob and DeviceInfo forked repos
2018-05-18 17:13:00 -04:00

62 lines
1.7 KiB
JavaScript

import {
Alert,
} from 'react-native';
import {
setJSExceptionHandler,
setNativeExceptionHandler,
} from 'react-native-exception-handler';
import {Client4} from 'mattermost-redux/client';
import {logError} from 'mattermost-redux/actions/errors';
import {close as closeWebSocket} from 'mattermost-redux/actions/websocket';
import {purgeOfflineStore} from 'app/actions/views/root';
import {
captureException,
initializeSentry,
LOGGER_JAVASCRIPT,
LOGGER_NATIVE,
} from 'app/utils/sentry';
import {app, store} from 'app/mattermost';
const errorHandler = (e, isFatal) => {
console.warn('Handling Javascript error ' + JSON.stringify(e)); // eslint-disable-line no-console
const {dispatch, getState} = store;
captureException(e, LOGGER_JAVASCRIPT, store);
const translations = app.getTranslations();
closeWebSocket()(dispatch, getState);
if (Client4.getUrl()) {
logError(e)(dispatch, getState);
}
if (isFatal) {
Alert.alert(
translations['mobile.error_handler.title'],
translations['mobile.error_handler.description'],
[{
text: translations['mobile.error_handler.button'],
onPress: () => {
// purge the store
purgeOfflineStore()(dispatch, getState);
},
}],
{cancelable: false}
);
}
};
const nativeErrorHandler = (e) => {
console.warn('Handling native error ' + JSON.stringify(e)); // eslint-disable-line no-console
captureException(e, LOGGER_NATIVE, store);
};
export function initializeErrorHandling() {
initializeSentry();
setJSExceptionHandler(errorHandler, false);
setNativeExceptionHandler(nativeErrorHandler, false);
}