33const Lab = require ( 'lab' )
44const Code = require ( 'code' )
55const Hapi = require ( 'hapi' )
6+ const Boom = require ( 'boom' )
67
78const 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