@@ -6,18 +6,25 @@ const createContent = require('./content')
66
77const getBody = ( content , callback ) => {
88 gzip ( content , ( err , buffer ) => {
9- if ( err ) return callback ( err )
10- const body = buffer . toString ( 'base64' )
11- callback ( null , body )
9+ try {
10+ if ( err ) return callback ( err )
11+ const body = buffer . toString ( 'base64' )
12+ callback ( null , body )
13+ } catch ( error ) {
14+ callback ( error )
15+ }
1216 } )
1317}
1418
15- const getIndexResponse = ( options , callback ) => {
16- const content = createContent ( options )
19+ const getIndexResponse = ( content , callback ) => {
1720 getBody ( content , ( err , body ) => {
18- if ( err ) return callback ( err )
19- const response = createIndexResponse ( body )
20- callback ( null , response )
21+ try {
22+ if ( err ) return callback ( err )
23+ const response = createIndexResponse ( body )
24+ callback ( null , response )
25+ } catch ( error ) {
26+ callback ( error )
27+ }
2128 } )
2229}
2330
@@ -56,11 +63,19 @@ const createFaviconResponse = ({
5663} )
5764
5865const getResponse = ( req , options , callback ) => {
59- const opts = extendOptions ( options )
60- if ( req . url === '/favicon.ico' ) {
61- return callback ( null , createFaviconResponse ( opts ) )
66+ try {
67+ const opts = extendOptions ( options )
68+
69+ if ( req . url === '/favicon.ico' ) {
70+ const favicon = createFaviconResponse ( opts )
71+ return callback ( null , favicon )
72+ }
73+
74+ const content = createContent ( options )
75+ getIndexResponse ( content , callback )
76+ } catch ( error ) {
77+ callback ( error )
6278 }
63- getIndexResponse ( opts , callback )
6479}
6580
6681const extendOptions = options => {
0 commit comments