@@ -10,7 +10,7 @@ const UTILS = require('./utils.js');
1010const fs = require ( 'fs' ) ; // Require Node.js file system
1111const path = require ( 'path' ) ; // Require Node.js path
1212const compression = require ( './compression' ) ; // Require compression lib
13- const { ResponseError, FileError } = require ( './errors' ) ; // Require custom errors
13+ const { ResponseError, FileError, ApiError } = require ( './errors' ) ; // Require custom errors
1414
1515// Lazy load AWS S3 service
1616const S3 = ( ) => require ( './s3-service' ) ;
@@ -85,15 +85,15 @@ class RESPONSE {
8585 return asArr
8686 ? this . _headers
8787 : Object . keys ( this . _headers ) . reduce (
88- ( headers , key ) =>
89- Object . assign ( headers , { [ key ] : this . _headers [ key ] . toString ( ) } ) ,
90- { }
91- ) ; // return all headers
88+ ( headers , key ) =>
89+ Object . assign ( headers , { [ key ] : this . _headers [ key ] . toString ( ) } ) ,
90+ { }
91+ ) ; // return all headers
9292 return asArr
9393 ? this . _headers [ key . toLowerCase ( ) ]
9494 : this . _headers [ key . toLowerCase ( ) ]
95- ? this . _headers [ key . toLowerCase ( ) ] . toString ( )
96- : undefined ;
95+ ? this . _headers [ key . toLowerCase ( ) ] . toString ( )
96+ : undefined ;
9797 }
9898
9999 // Issue #130
@@ -131,9 +131,9 @@ class RESPONSE {
131131
132132 this . header ( 'Content-Type' , 'application/json' ) . send (
133133 ( cb ? cb . replace ( ' ' , '_' ) : 'callback' ) +
134- '(' +
135- this . _serializer ( body ) +
136- ')'
134+ '(' +
135+ this . _serializer ( body ) +
136+ ')'
137137 ) ;
138138 }
139139
@@ -193,8 +193,8 @@ class RESPONSE {
193193 typeof expires === 'function'
194194 ? expires
195195 : typeof callback === 'function'
196- ? callback
197- : ( e ) => {
196+ ? callback
197+ : ( e ) => {
198198 if ( e ) this . error ( e ) ;
199199 } ;
200200
@@ -236,10 +236,10 @@ class RESPONSE {
236236 cookieString +=
237237 opts . maxAge && ! isNaN ( opts . maxAge )
238238 ? '; MaxAge=' +
239- ( ( opts . maxAge / 1000 ) | 0 ) +
240- ( ! opts . expires
241- ? '; Expires=' + new Date ( Date . now ( ) + opts . maxAge ) . toUTCString ( )
242- : '' )
239+ ( ( opts . maxAge / 1000 ) | 0 ) +
240+ ( ! opts . expires
241+ ? '; Expires=' + new Date ( Date . now ( ) + opts . maxAge ) . toUTCString ( )
242+ : '' )
243243 : '' ;
244244
245245 // path (String): Path for the cookie
@@ -248,14 +248,14 @@ class RESPONSE {
248248 // secure (Boolean): Marks the cookie to be used with HTTPS only
249249 cookieString += opts . secure && opts . secure === true ? '; Secure' : '' ;
250250
251- // sameSite (Boolean or String) Value of the “ SameSite” Set-Cookie attribute
251+ // sameSite (Boolean or String) Value of the " SameSite" Set-Cookie attribute
252252 // see https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00#section-4.1.1.
253253 cookieString +=
254254 opts . sameSite !== undefined
255255 ? '; SameSite=' +
256- ( opts . sameSite === true
257- ? 'Strict'
258- : opts . sameSite === false
256+ ( opts . sameSite === true
257+ ? 'Strict'
258+ : opts . sameSite === false
259259 ? 'Lax'
260260 : opts . sameSite )
261261 : '' ;
@@ -323,7 +323,7 @@ class RESPONSE {
323323 let buffer , modified ;
324324
325325 let opts = typeof options === 'object' ? options : { } ;
326- let fn = typeof callback === 'function' ? callback : ( ) => { } ;
326+ let fn = typeof callback === 'function' ? callback : ( ) => { } ;
327327
328328 // Add optional parameter support
329329 if ( typeof options === 'function' ) {
@@ -440,16 +440,16 @@ class RESPONSE {
440440 opts . methods
441441 ? opts . methods
442442 : acam
443- ? acam
444- : 'GET, PUT, POST, DELETE, OPTIONS'
443+ ? acam
444+ : 'GET, PUT, POST, DELETE, OPTIONS'
445445 ) ;
446446 this . header (
447447 'Access-Control-Allow-Headers' ,
448448 opts . headers
449449 ? opts . headers
450450 : acah
451- ? acah
452- : 'Content-Type, Authorization, Content-Length, X-Requested-With'
451+ ? acah
452+ : 'Content-Type, Authorization, Content-Length, X-Requested-With'
453453 ) ;
454454
455455 // Optional CORS headers
@@ -500,8 +500,8 @@ class RESPONSE {
500500 date && typeof date . toUTCString === 'function'
501501 ? date
502502 : date && Date . parse ( date )
503- ? new Date ( date )
504- : new Date ( ) ;
503+ ? new Date ( date )
504+ : new Date ( ) ;
505505 this . header ( 'Last-Modified' , lastModified . toUTCString ( ) ) ;
506506 }
507507 return this ;
@@ -559,10 +559,10 @@ class RESPONSE {
559559 } ,
560560 this . _request . interface === 'alb'
561561 ? {
562- statusDescription : `${ this . _statusCode } ${ UTILS . statusLookup (
563- this . _statusCode
564- ) } `,
565- }
562+ statusDescription : `${ this . _statusCode } ${ UTILS . statusLookup (
563+ this . _statusCode
564+ ) } `,
565+ }
566566 : { }
567567 ) ;
568568
@@ -596,13 +596,11 @@ class RESPONSE {
596596 error ( code , e , detail ) {
597597 const message = typeof code !== 'number' ? code : e ;
598598 const statusCode = typeof code === 'number' ? code : undefined ;
599- const errorDetail =
600- typeof code !== 'number' && e !== undefined ? e : detail ;
599+ const errorDetail = typeof code !== 'number' && e !== undefined ? e : detail ;
601600
602- const errorToSend =
603- typeof message === 'string'
604- ? new ResponseError ( message , statusCode , errorDetail )
605- : message ;
601+ const errorToSend = typeof message === 'string'
602+ ? new ApiError ( message , statusCode , errorDetail )
603+ : message ;
606604
607605 this . app . catchErrors ( errorToSend , this , statusCode , errorDetail ) ;
608606 } // end error
0 commit comments