-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create router errors #3047
Create router errors #3047
Conversation
@posva I wrote some unit tests, the PR is ready to be reviewed 😉 |
Bump on this? This would be really helpful for tracking down where promise rejections are coming from <3 |
It seems this PR can also solve #3027. +1 for it to be merged and released. |
@lmichelin could it be possible to export the exceptions so they can be imported (e.g. using |
@quentinus95 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @lmichelin
Now that errors are stable on vue-router-next, I think we could try to align the user API part to make migration easier.
Namely, we need:
- a
type
,from
property - an object (to simulate the enumeration) with the same properties as
NavigationFailureType
- an exported TS interface so users can type errors
We can also remove:
- the
name
and_name
properties - all the code to hack around Error extension and use plain errors (https://github.com/vuejs/vue-router-next/blob/master/src/errors.ts#L77-L90)
It's okay to have a few differences like the lack of from
and to
properties. Also, let me know if you don't have the time so I can pick it up. If you only manage to add a few things but not all, that's, of course, fine as well!
Link to RFC: vuejs/rfcs#150
Link to vue-router-next errors file: https://github.com/vuejs/vue-router-next/blob/master/src/errors.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realised you have a sample for an e2e test but it doesn't seem like you need it since you added a unit test already
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your help with this @lmichelin and sorry for the delay!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good morning @lmichelin and @posva. I discovered this PR while handling navigation duplicated errors in my application and have been tracking the changes in case it requires migration when we update vue-router
in the future.
I noted two places in the changes where NavigationFailureType.NAVIGATION_DUPLICATED
references were not updated after the keys were changed in NavigationFailureType
. I'm admittedly new to vue-router
internals, so apologies if I misunderstood something here. Thanks for your time.
@@ -104,7 +110,7 @@ export class History { | |||
// When the user navigates through history through back/forward buttons | |||
// we do not want to throw the error. We only throw it if directly calling | |||
// push/replace. That's why it's not included in isError | |||
if (!isExtendedError(NavigationDuplicated, err) && isError(err)) { | |||
if (!isRouterError(err, NavigationFailureType.NAVIGATION_DUPLICATED) && isError(err)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be renamed to NavigationFailureType.duplicated
.
@@ -51,7 +51,7 @@ export class AbstractHistory extends History { | |||
this.updateRoute(route) | |||
}, | |||
err => { | |||
if (isExtendedError(NavigationDuplicated, err)) { | |||
if (isRouterError(err, NavigationFailureType.NAVIGATION_DUPLICATED)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here as well.
You are right, I completely forgot these references 🙈 |
I just opened a new PR to fix this: #3204 |
I think this was a breaking change? We don't get the |
The errors were not documented and considered private. Checking navigation failures docs are on the way! |
I'd say that checking an |
+1 for this being a breaking change - once again I am back here to figure out why suddenly there are errors in my app where there weren't errors before (and the fact that it was merged and published without docs on how to do proper error checking also seems like a mistake) |
@posva - are these type constants exported from the package, so that I can inspect navigation errors in my application and handle them appropriately? I don't see anything which adds that, is it in another PR? |
I was checking As a workaround I'm now importing
On components I can now check |
Please check #3220 for the proposed documentation for errors. Your feedback could be valuable there |
This PR improves the way router errors are thrown.
4 router errors types have been created:
NavigationDuplicated
NavigationCancelled
NavigationRedirected
NavigationAborted
Before:
After: