Expected behaviour:
I have implemented auth().verifyPhoneNumber(phonenumber), and I would like to implement error handling by using a try catch block.
Code example:
try {
await auth().verifyPhoneNumber("+852 90815 ");
} catch (error) {
console.log(error.code);
}
;
Actual behaviour:
When this code is ran, no console has been registered and promise rejection is raised.
Possible Unhandled Promise Rejection (id: 19):
Error: [auth/invalid-phone-number] The format of the phone number provided is incorrect.
How do I implement this properly?
Thanks in advance.
Try
await auth().verifyPhoneNumber("+852 90815 ").catch((e)=>{
console.log(e);
});
Instead
Related
I am currently working on an IoT project which requires service discovery (I am in the Android side). I decided to use react-native-zeroconf and I encountered a problem.
There is a warning Error: Request failed with status code 500 once I called .scan() method.
I have already added permission into the AndroidManifest file. Thank you in advance.
Edit: remove async from function
export function scanmDNS() {
const zeroconf = new Zeroconf();
zeroconf.scan();
const res = zeroconf.getServices();
console.log({ res });
zeroconf.stop();
}
Object {
"res": Object {},
}
Possible Unhandled Promise Rejection (id: 0):
Error: Request failed with status code 500
createError#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:224752:26
settle#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:224742:25
onloadend#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:224619:15
dispatchEvent#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:33843:31
setReadyState#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:32985:29
__didCompleteResponse#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:32783:29
emit#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:4940:42
__callFunction#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:5979:36
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:5707:31
__guard#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:5933:15
callFunctionReturnFlushedQueue#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:5706:21
callFunctionReturnFlushedQueue#[native code]
Possible Unhandled Promise Rejection (id: 1):
There are two ways to handle Promises, since you're using async/await syntax your response should use the await keyword also you are wrapping your response in an object which you shouldn't (without assigning it to a property).
const res = await zeroconf.getServices();
console.log(res)
The other way would be
zeroconf.getServices()
.then((res) => {
console.log(res) //do whatever you want to do with your response here
})
.catch((err) => {
console.log(err) //handle errors here.
}
Not sure if this will solve your problem but hope it leads you to your solution :)
I'm new to react-native, I want to fetch some data from my local laravel server, but I fire the mobx action I get the following errors:
Network Error
[Unhandled promise rejection: Error: Network Error]
This is my mobx action (I'm using flow, similar to async/await), I get 'fire' log but after that I get the error above:
listProducts = flow( function*(payload)
{
console.log('fire');
try
{
let response = yield axios.get('http://192.168.1.39:8000/api/products', { params: payload });
this.posts = response.data;
this.pagination = response.data.pagination;
console.log(response);
//return response;
}
catch (error)
{
console.error(error);
throw error;
}
});
As you can see I'm using my local IP instead of localhost, I'm also testing my app on my android device using EXPO connected to the same network as my dev laptop.
Ciao, I can't see errors on your code. Try to follow this guide to handle Unhandled promise rejection. Could help you to find a clue.
In brief the guide suggest to use axios interceptors:
axios.interceptors.response.use(
response => response,
error => {}
)
Using react native, getting a Possible Unhandled Promise Rejection error when using a firebase.Promise (https://firebase.google.com/docs/reference/js/firebase.Promise) in a redux action thunk (https://redux.js.org/advanced/asyncactions#actions-js-asynchronous), eg.
....
console.log(`Reuthenticating for user ${user.displayName}, ${user.email}`)
credentials = 'intentionally bad credential type'
user.reauthenticateAndRetrieveDataWithCredential(credentials)
.then(
(res) => {console.log(`Reauth complete: ${res}`)},
(error) => {console.log(`Something bad happend ${error}`)})
....
(authenticating as recommended here (https://firebase.google.com/docs/auth/web/manage-users#re-authenticate_a_user) via reauthenticateAndRetrieveDataWithCredential (https://firebase.google.com/docs/reference/js/firebase.User#reauthenticateAndRetrieveDataWithCredential)) produces the message
[18:45:12] Reuthenticating for user me, me#gmail.com
[18:45:14] Possible Unhandled Promise Rejection (id: 0):
[18:45:14] [Error: reauthenticateAndRetrieveDataWithCredential failed: First argument "credential" must be a valid credential.]
without printing the console.log() message (which indicates to me that this is not just a warning, but an actual error). Even though I am providing an onReject callback to .then() (https://firebase.google.com/docs/reference/js/firebase.Promise#then).
Some other SO posts suggest appending a .catch() to the promise (rather then providing an on onReject fallback callback in the promise's .then() like I do), but since am using a thunk action here, this is not recommended (see https://github.com/facebook/react/issues/6895#issuecomment-281405036). Anyone know what could be happening here or some steps to debug further?
I've started to work with protractor + Jasmine for E2E testing.
The idea is to do an invalid operation and catch the exception:
expect(function () { return documentsPanel.clickUploadButtonError(); }).toThrow();
The documentsPanel is just a page object with multiple page actions. This is how I'm defining the method:
this.clickUploadButtonError = function () {
return uploadButton.click().thenCatch(function (err) {
throw('Cannot click upload button.');
});
};
The idea is for expect to pass by catching the error but my test still fails as uploadButton.click() throws a Selenium error:
Failed: unknown error: Element ... is not clickable at point (263, 131).
Any ideas on how can Jasmine catch the Selenium error?
You can provide an error callback explicitly:
return uploadButton.click().then(function success() {
console.log("Click was successful");
}, function failure(error) {
console.log("Click was unsuccessful");
console.log(error);
});
As a side note, if you are interested in tackling the "Element is not clickable" errors, please see this summary of the things to try.
There's some error rasied on my page, and vue-router warning:
[vue-router] Uncaught error during transition:
I wonder how to catch it and remove this warning? From vue-router's doc, I cannot find a hook function handle errors. I also tried to catch error
router.beforeEach((transition) => {
try {
transition.next()
} catch (e) {
transition.abort()
console.log('route caught', e)
}
})
Although I can catch the error now, but the warning still raised, and I don't know if I did the right thing.
And there is another warning when error raised
[vue-router] transition.next() should be called only once.
How to get rid of this?
You cannot use a promise AND call next use either one or the other