fix(server): handle decodeURI error (#5243)

This commit is contained in:
phof 2019-03-16 21:33:22 +00:00 committed by Pooya Parsa
parent 37cd24c261
commit 5b7f6d78ec

View File

@ -7,10 +7,10 @@ import { getContext } from '@nuxt/utils'
export default ({ options, nuxt, renderRoute, resources }) => async function nuxtMiddleware(req, res, next) { export default ({ options, nuxt, renderRoute, resources }) => async function nuxtMiddleware(req, res, next) {
// Get context // Get context
const context = getContext(req, res) const context = getContext(req, res)
const url = decodeURI(req.url)
res.statusCode = 200
try { try {
const url = decodeURI(req.url)
res.statusCode = 200
const result = await renderRoute(url, context) const result = await renderRoute(url, context)
await nuxt.callHook('render:route', url, result, context) await nuxt.callHook('render:route', url, result, context)
const { const {
@ -82,6 +82,9 @@ export default ({ options, nuxt, renderRoute, resources }) => async function nux
return err return err
} }
if (err.name === 'URIError') {
err.statusCode = 400
}
next(err) next(err)
} }
} }