diff --git a/README.md b/README.md index 1884bb3..a94fb57 100755 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ You can set decode. ### `onDecodeError` -- Default: `(error, req, res, next) => next(error)` +- Default: `(error, req, res, next) => next()` You can set callback when there is an error in the decode. diff --git a/lib/module.js b/lib/module.js index c89d150..a4cffa5 100644 --- a/lib/module.js +++ b/lib/module.js @@ -2,7 +2,7 @@ async function redirectModule (moduleOptions) { const defaults = { rules: [], onDecode: (req, res, next) => decodeURI(req.url), - onDecodeError: (error, req, res, next) => next(error), + onDecodeError: (_error, _req, _res, next) => next(), statusCode: 302 } diff --git a/test/module.test.js b/test/module.test.js index 5b437f6..7d11c01 100644 --- a/test/module.test.js +++ b/test/module.test.js @@ -52,6 +52,12 @@ const testSuite = () => { expect(html).toContain('ab') }) + test('redirect with malformed URI', async () => { + await expect(get('/%83')).rejects.toMatchObject({ + statusCode: 400 + }) + }) + test('redirect error due to malformatted target url', async () => { const requestOptions = { uri: url('/errorInTo'), @@ -195,6 +201,9 @@ describe('error', () => { if (req.url === '/error') { throw e } + }, + onDecodeError: (error, _req, _res, next) => { + next(error) } } })