-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #285 from htdangkhoa/develop
fix: #282 Custom error handler not being reached
- Loading branch information
Showing
5 changed files
with
52 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const pureHttp = require('../..'); | ||
|
||
module.exports = function () { | ||
const app = pureHttp(); | ||
|
||
app.get( | ||
'/custom', | ||
(_req, _res, _next) => { | ||
throw new Error('bad'); | ||
}, | ||
/* istanbul ignore next */ | ||
// ignore coverage for this function because it will never be called. | ||
(req, res, _next) => { | ||
res.send('good'); | ||
}, | ||
); | ||
|
||
app.use((error, req, res, _next) => { | ||
res.send('Something went wrong.', 500); | ||
}); | ||
|
||
return app; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* eslint-disable global-require */ | ||
/* eslint-disable no-unused-vars */ | ||
const supertest = require('supertest'); | ||
|
||
describe('ALL /not-found', () => { | ||
it(`The status should be 404.`, async () => { | ||
const app = require('./custom')(); | ||
|
||
const request = supertest(app); | ||
|
||
const res = await request.get('/custom'); | ||
|
||
expect(res.statusCode).toBe(500); | ||
expect(res.text).toBe('Something went wrong.'); | ||
}); | ||
}); |