I am using RN 0.61.5, and set my custom error handler ErrorUtils.setGlobalHandler(customHandler);.
export const setGlobalErrorHandler = once(nativeModule => {
console.log("inside setGlobalErrorHandler")
const originalHandler = ErrorUtils.getGlobalHandler();
console.log("originalHandler:", originalHandler)
async function handler(error, fatal) {
if (__DEV__) {
console.log("is dev env")
return originalHandler(error, fatal);
}
console.log("inside setGlobalErrorHandler, is not dev env")
if (!isError(error)) {
console.log("is not error type")
await nativeModule.logPromise(`Unknown Error: ${error}`);
return originalHandler(error, fatal);
}
try {
console.log("create JS error")
const stackFrames = await StackTrace.fromError(error, { offline: true });
await nativeModule.recordErrorPromise(createNativeErrorObj(error, stackFrames, false));
} catch (e) {
console.log("met with error:", JSON.stringify(e));
// do nothing
}
return originalHandler(error, fatal);
}
ErrorUtils.setGlobalHandler(handler);
console.log("newHandler:", ErrorUtils.getGlobalHandler())
return handler;
});
Did a small test by throwing a JS error when a button is clicked, but my customHandler does not get invoked. The app doesn't show an RED color error box nor crashes. I am suspecting that some other places are handling the error. I did implement any ErrorBoundary that catches all uncaught errors
Related
Currently i am facing the "service worker navigation preload request was cancelled before 'preloadresponse' settled. if you intend to use 'preloadresponse', use waituntil() or respondwith() to wait for the promise to settle" and how can i load all my method sequence?
async mounted() {
this.startLoading();
try {
await this.initializeData();
} catch (error) {
// error
}
},
methods: {
initializeData()
{
axios.all([
this.get_list_class(),
this.get_list_library(),
this.get_list_teacher(),
this.GetOrderID(),
// this.getVideoContent();
this.getProduct(),
this.checkCustRegisterInfo(),
this.checkCustRegister(),
this.checkTicket(),
this.scrollToTop(),
]).then(axios.spread((...responses) => {})).catch(errors => {
console.log('Not load');
})
}
}
I have this Button component which displays a spinner when loading = true, to handle loading states, the switch right here is from track to tracking, those are the 2 texts that show up before and after loading.
I'm using the devTools to see the state changing, but the problem is that right after loading=false the spinner stops and just for a second after switching to "tracking" it shows s the word "track" again.
Here's the code:
// Following
const isTracked = computed((): boolean =>
store.state.user.following.includes(userID.value)
)
const isLoadingTracking = ref(false)
const handleTracking = async (): Promise<void> => {
try {
isLoadingTracking.value = true
if (isTracked.value) await unfollow(userID.value)
else await follow(userID.value)
store.dispatch('getProfileData')
} catch (err) {
store.commit('notify', { key: 'error', status: 'ERROR' })
} finally {
isLoadingTracking.value = false
}
}
store.dispatch('getProfileData') is asynchronous code.
This means that, technically, the finally {} block executes before the code in your getProfileData action finishes.
To fix it, place an await in front of store.dispatch('getProfileData'):
try {
isLoadingTracking.value = true
if (isTracked.value) await unfollow(userID.value)
else await follow(userID.value)
await store.dispatch('getProfileData')
} catch (err) {
store.commit('notify', { key: 'error', status: 'ERROR' })
} finally {
isLoadingTracking.value = false
}
Alternate syntax for the above block:
try {
isLoadingTracking.value = true
await (isTracked.value ? unfollow : follow)(userID.value)
await store.dispatch('getProfileData')
} catch (err) {
store.commit('notify', { key: 'error', status: 'ERROR' })
} finally {
isLoadingTracking.value = false
}
I am trying to introduce jest to an existing project.
But now, when testing after the first introduction of Zest, I met this error message.
I tried debugging but couldn't find how to fix it.
How do I solve it?
I've tried deleting alim (alim inside try and alim inside catchch statement), and throwing an error with Throw new Error(), but it still shows the same error.
//error
[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "TypeError: this.alim is not a function".] {
code: 'ERR_UNHANDLED_REJECTION'
}
<template>
...
<!-- alert -->
<alim :open="snackbar" :txt="text" :color="color" #reset="emitReset"></alim>
</template>
<script>
async reload(num) {
if (num === 0) {
this.clear();
}
//검색할경우 페이징 초기화
if (num === 1) {
this.page = 1;
}
try {
bus.$emit("start:spinner");
const res = await this.__getResponse("user/GET_USER_LIST", {
size: this.size,
page: this.page,
searchText: this.searchText,
});
if (res.errorCode !== 200) {
this.alim(res.errorMessage, this.errorColor);
return;
}
const data = res.homepageUserMaster;
this.list = data.data;
this.len = data.last_page;
} catch (error) {
this.alim(error, this.errorColor);
} finally {
bus.$emit("end:spinner");
}
},
</script>
//alimMixin
alim(text, color) {
this.snackbar = true;
this.text = text;
this.color = color;
const _this = this;
let time = setTimeout(function () {
_this.snackbar = false;
_this.text = "";
_this.color = "";
clearInterval(time);
if (_this.closeModal === true) {
_this.close();
}
}, 3000);
},
I have successfully implemented google-signin into my RN app with Firebase using code below.
When I click button first time it creates FB account....then subsequent times it logs me in.
Everything works fine.....but then from time to time when I click to log in, it returns the error code of statusCodes.IN_PROGRESS
I want to be able to handle this error (by terminating sign-in or something??) but have no idea how.....can anyone help?
p.s. exact line of code causing error = const {accessToken, idToken} = await GoogleSignin.signIn();.....its also giving me this warning Warning: previous promise did not settle and was overwritten. You've called "signIn" while "signIn" was already in progress and has not completed yet.
import firebase from '#react-native-firebase/app';
import auth from '#react-native-firebase/auth';
import {GoogleSignin, statusCodes} from '#react-native-community/google-signin';
import {LoginManager, AccessToken} from 'react-native-fbsdk';
export const _getFbGoogleCredential = async () => {
await GoogleSignin.hasPlayServices();
const {accessToken, idToken} = await GoogleSignin.signIn();
const firebaseCredential = await auth.GoogleAuthProvider.credential(idToken, accessToken);
return firebaseCredential;
};
export const _googleSignIn = async () => {
try {
const firebaseCredential = await _getFbGoogleCredential();
const fbUserObj = await auth().signInWithCredential(firebaseCredential);
} catch (error) {
if (error.code === 'auth/account-exists-with-different-credential') {
//xx
} else if (error.code === statusCodes.SIGN_IN_CANCELLED) {
//xx
} else if (error.code === statusCodes.IN_PROGRESS) {
//HERE IS THE ISSUE
} else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
//xx
} else {
//xx
}
}
};
I also had this same error
Warning: previous promise did not settle and was overwritten. You've called "signIn" while "signIn" was already in progress and has not completed yet.
and i was able to fix is by NOT using GoogleSigninButton that comes with the package #react-native-google-signin/google-signin
The GoogleSigninButton has a bug so just use any other button component...weird fix but hey it works. Behold the culprit
I'm trying to make an singleton Class that uses AsyncStorage.
Follow the code:
import ReactNative, { AsyncStorage } from "react-native";
export default class StorageHandler {
static async getItem(key) {
try {
return await AsyncStorage.getItem(key);
} catch (error) {
console.log(error);
}
}
static async setItem(key, value) {
console.log("Values on StorageHandler", key, value);
try {
await AsyncStorage.setItem(key, value);
} catch (error) {
console.error(error);
}
}
}
I'm using the setItem function in a function in a component, follow the function:
async onIds(device) {
console.log("Device info: ", device);
try {
await StorageHandler.setItem(StorageConstants.ONESIGNAL_ID, device.userId)
} catch (error) {
console.log(error);
}
}
But i'm getting an error :
ReferenceError: value is not defined;
The log on StorageHandler returns :
Values on StorageHandler onesignal_id xxxxx-xxxxx-xxxx-xxxx-xxxxxx
So, what i'm doing wrong ?
And most important, why is it happening?
I'm starting at react-native so i'm a bit lost.
Edit1 :
Removed Resolve from getItem catch.
I deleted the react-native app from my device and recompile without livereload and it worked.
Maybe it's something wrong with livereload.
Edit: The chrome debugger by default have the option "Pause on Exceptions" on.
Sometimes the promises didn't return an error, and by the act of livereload it seems the chrome is pausing the promises doe to the previous error.
Just turn "Pause on Exceptions" off and it work like a charm.