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

How to redirect to another route onDecodeError #124

Open
MooseSaeed opened this issue Dec 8, 2022 · 1 comment
Open

How to redirect to another route onDecodeError #124

MooseSaeed opened this issue Dec 8, 2022 · 1 comment

Comments

@MooseSaeed
Copy link

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
Copy link
Author

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)
			}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant