Skip to content

Commit ed1a366

Browse files
committed
test whether error other than 503 would get handled
1 parent 0b556a8 commit ed1a366

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

test/plugin-is-disabled-by-default.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const Lab = require('lab')
44
const Code = require('code')
55
const Hapi = require('hapi')
6+
const Boom = require('boom')
67

78
const server = new Hapi.Server()
89

@@ -20,9 +21,7 @@ experiment('plugin-is-disabled-by-default,', () => {
2021
const routeOptions = {
2122
path: '/no-options',
2223
method: 'GET',
23-
handler: () => {
24-
return new Error('failure')
25-
}
24+
handler: () => new Error('failure')
2625
}
2726

2827
server.route(routeOptions)
@@ -39,4 +38,27 @@ experiment('plugin-is-disabled-by-default,', () => {
3938
Code.expect(payload.message).to.equal('An internal server error occurred')
4039
Code.expect(payload.error).to.equal('Internal Server Error')
4140
})
41+
42+
test('does not render the gorgeous error view for 503 errors', async () => {
43+
const routeOptions = {
44+
path: '/503-unhandled',
45+
method: 'GET',
46+
handler: () => Boom.serverUnavailable('not ready')
47+
48+
}
49+
50+
server.route(routeOptions)
51+
52+
const request = {
53+
url: routeOptions.path,
54+
method: routeOptions.method
55+
}
56+
57+
const response = await server.inject(request)
58+
const payload = JSON.parse(response.payload || '{}')
59+
60+
Code.expect(response.statusCode).to.equal(503)
61+
Code.expect(payload.message).to.equal('not ready')
62+
Code.expect(payload.error).to.equal('Service Unavailable')
63+
})
4264
})

0 commit comments

Comments
 (0)