Skip to content

Commit

Permalink
fastify#92 test: add test for onError option
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbain committed Aug 8, 2023
1 parent d44dbf8 commit b296029
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ function fastProxy (opts = {}) {
}
request(reqParams, (err, response) => {
if (err) {

// allow for errors to be passed to a custom callback
if (onError) {
onError(err, req, res)
Expand Down
17 changes: 17 additions & 0 deletions test/4.opts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ nock('http://dev.com')
url: 'http://dev.com'
})

nock('http://dev.error')
.get('/service/error')
.replyWithError('Error')

describe('fast-proxy smoke', () => {
it('init', async () => {
const fastProxy = require('../index')({
Expand All @@ -40,6 +44,10 @@ describe('fast-proxy smoke', () => {
queryString: { age: 33 },
onResponse (req, res, stream) {
pump(stream, res)
},
onError (err, req, res) {
res.statusCode = 418
res.send(err)
}
})
})
Expand Down Expand Up @@ -99,6 +107,15 @@ describe('fast-proxy smoke', () => {
.expect(302)
})

it('should allow for errors to be handled', async () => {
await request(gHttpServer)
.get('/service/error')
.set('base', 'http://dev.com')
.then(response => {
expect(response.statusCode).to.equal(418)
})
})

it('close all', async () => {
close()
await gateway.close()
Expand Down

0 comments on commit b296029

Please sign in to comment.