3
3
const Lab = require ( 'lab' )
4
4
const Code = require ( 'code' )
5
5
const Hapi = require ( 'hapi' )
6
+ const Boom = require ( 'boom' )
6
7
7
8
const server = new Hapi . Server ( )
8
9
@@ -20,9 +21,7 @@ experiment('plugin-is-disabled-by-default,', () => {
20
21
const routeOptions = {
21
22
path : '/no-options' ,
22
23
method : 'GET' ,
23
- handler : ( ) => {
24
- return new Error ( 'failure' )
25
- }
24
+ handler : ( ) => new Error ( 'failure' )
26
25
}
27
26
28
27
server . route ( routeOptions )
@@ -39,4 +38,27 @@ experiment('plugin-is-disabled-by-default,', () => {
39
38
Code . expect ( payload . message ) . to . equal ( 'An internal server error occurred' )
40
39
Code . expect ( payload . error ) . to . equal ( 'Internal Server Error' )
41
40
} )
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
+ } )
42
64
} )
0 commit comments