nuxt-community / redirect-module

No more cumbersome redirects for Nuxt 2!
MIT License
312 stars 17 forks source link

How to redirect to another route onDecodeError #124

Open MooseSaeed opened 1 year ago

MooseSaeed commented 1 year ago

I'm having an issue where I'm getting a lot of URI Malformed errors on Sentry from routes that are valid but has %2 at the end of it. So I need a way to remove the %2 whenever there is an error while decoding and redirect the user to that route.

How can I redirect the user to a different route onDecodeError?

MooseSaeed commented 1 year ago

Got that sorted out

            if (/^.*(%2)$/.test(req.url)) {
                res.setHeader('Location', encodeURI(req.url.slice(0, -2)))
                res.statusCode = 302
                res.end()
            } else {
                next(error)
            }