Skip to content
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

onError does not capture errors thrown in redirect callback #3201

Closed
trainiac opened this issue May 15, 2020 · 4 comments · Fixed by #3251
Closed

onError does not capture errors thrown in redirect callback #3201

trainiac opened this issue May 15, 2020 · 4 comments · Fixed by #3251

Comments

@trainiac
Copy link
Contributor

Version

3.1.6

Reproduction link

https://codepen.io/trainiac/pen/rNOZvRO?editors=1112

Steps to reproduce

  1. create route config like
{
    path: '/oldpath/:part',
    redirect: (to: Route) => {
      if(to.ooopsmistake.part) {
        return `/newpath/${to.params.part}`
      }
      return '/newpath/'
    },
  }

What is expected?

When router.push('/oldpath/test'). an error is throw becuase there is no oopsmistake property on the to route. This should be caught in router.onError.

What is actually happening?

It's only caught in router.push('/oldpath/test').catch(err is here)

@posva
Copy link
Member

posva commented May 15, 2020

FYI, the error will still be thrown/rejecetd by router.push even if it's sent to onError

@trainiac
Copy link
Contributor Author

Makes sense. The issue is now, for ssr, if you just want to use onError to manager errors and add a push().catch(noop) to swallow rejections, a thrown error in the redirect callbacks leaves you hanging.

@raulcabello
Copy link
Contributor

I'm also interested in this. Would you accept a pull request for this feature?

@posva
Copy link
Member

posva commented Jun 30, 2020

yes, go ahead

posva pushed a commit that referenced this issue Jul 3, 2020
…3251)

* feat(errors): capture errors thrown in redirect callback in onError

Resolves #3201

* feat(errors): capture errors thrown in redirect callback in onError

try catch just router.match

Resolves #3201

* feat(errors): capture errors thrown in redirect callback in onError

remove unnecessary if

Resolves #3201

Co-authored-by: Raul Cabello <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants