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
Related
The following error occurs when I run my react native project on an android real device.
Unexpected Identifier 'cat' try statements must have at least a catch or finally block no stack
How do I solve it ?
Could you please share some code where this is happening
The error says that somewhere in your code you have try {} statement without catch {} or finally {}
To fix it search where you have try statements and add catch or finally to it.
Example:
try {
// Some code
} catch (error) {
// Handle error
} finally {
// On finish
}
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
I've custom throw at component created() method.
throw new Error(`Cookie ${cookieName} not exist.`);
And vue logs it into console:
[Vue warn]: Error in created hook: "Error: Cookie showLanguageInfo not exist."
How can I implement throwing this error without this vue log?
Please remove the below line from created hook. The below line is throwing error without any real exception.
throw console.error("error");
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.
Here is the background of the question : I'm following the kick-off-koa using Koa 2. But the exercises in the kick-off are designed for Koa 1. I've created an issue for this problem of Koa 2 : Task of error handler with Koa 2 cannot pass.
For short, my problem is how to display a custom error page when a 500 error happens.
Here are the codes :
// error handler middleware
function errorHandler(ctx, next) {
try {
return next();
}
catch(err) {
ctx.status = err.status || 500;
// I would like to display the custom message as follows
ctx.body = 'Oops! internal server error';
// with emitting the error event, don't work
// ctx.app.emit('error', err, ctx);
}
}
// to generate error
app.use(router.get('/error', ctx => {
ctx.throw('oops', 500);
}));
But my page of error is always displaying as "Internal Server Error", which is the default message. It seems that ctx.body = 'Oops! internal server error'; couldn't modify the page.
Thanks for the helps!
If you are using Koa2, you don't have to return inside middleware, instead, use await. And by the way, your middleware function MUST be an async function.
Here is an example of a combined 404 and 500 middleware:
app.use(async (ctx, next) => {
try {
await next()
if (ctx.status === 404) ctx.throw(404)
} catch (err) {
console.error(err)
ctx.status = err.status || 500
ctx.body = errorPage.render({ // Use your render method
error: err,
})
}
})
// Your normal routes here
First, Koa awaits for the next middleware in the chain (which is your normal routes). If nothing is found or an error occurred, the middleware chain goes backwards and the next line is executed, which throws a 404 and its captured inside the catch.
Now in the catch statement, you can get either 404, 500 (by default) or 5xx if other error occurred.
The body of the page is also set with a render of your template and passing the error to the template so you can make use of it.
You don't have to emit the error as this is the last catch in the chain.