Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
fix: fix client-side getInitialData redirects
Browse files Browse the repository at this point in the history
Fixes #121 and #118. Improves handling of unhandled errors.
  • Loading branch information
IlyaSemenov committed Oct 11, 2018
1 parent cce861f commit c923fb1
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions app/client-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,26 @@ const updateDataStore = (id, data) => {

const handleError = err => {
if (err instanceof ReamError) {
if (err.code === 'REDIRECT') {
const url = err.redirectURL
if (/^(\w+:)?\/\//.test(url)) {
window.location.assign(url)
} else {
router.push(url)
}
app.setError(err)
return true
}
console.error(err)
return false
}

const handleRouteGuardError = (err, next) => {
if (err instanceof ReamError && err.code === 'REDIRECT') {
const url = err.redirectURL
if (/^(\w+:)?\/\//.test(url)) {
window.location.assign(url)
next(false)
} else {
app.setError(err)
next(url)
}
} else if (handleError(err)) {
next()
} else {
console.error(err)
next(false)
}
}

Expand Down Expand Up @@ -79,8 +87,7 @@ router.beforeResolve(async (to, from, next) => {
next()
} catch (err) {
err.errorPath = to.path
handleError(err)
next()
handleRouteGuardError(err, next)
}
})

Expand All @@ -104,8 +111,7 @@ Vue.mixin({
next()
} catch (err) {
err.url = to.path
handleError(err)
next()
handleRouteGuardError(err, next)
}
}
})
Expand Down Expand Up @@ -137,6 +143,7 @@ main()
mountApp(app)
})
.catch(err => {
handleError(err)
mountApp(app)
if (handleError(err)) {
mountApp(app)
}
})

0 comments on commit c923fb1

Please sign in to comment.