@@ -262,7 +262,10 @@ export class Response extends Macroable implements ResponseContract {
262262 /**
263263 * Stream the body to the response and handles cleaning up the stream
264264 */
265- private streamBody ( body : ResponseStream , errorCallback ?: ( ( error : NodeJS . ErrnoException ) => any ) ) {
265+ private streamBody (
266+ body : ResponseStream ,
267+ errorCallback ?: ( ( error : NodeJS . ErrnoException ) => [ string , number ?] ) ,
268+ ) {
266269 return new Promise ( ( resolve ) => {
267270 let finished = false
268271
@@ -280,7 +283,7 @@ export class Response extends Macroable implements ResponseContract {
280283 destroy ( body )
281284
282285 if ( typeof ( errorCallback ) === 'function' ) {
283- this . endResponse ( errorCallback ( error ) )
286+ this . endResponse ( ... errorCallback ( error ) )
284287 } else {
285288 this . endResponse (
286289 error . code === 'ENOENT' ? 'File not found' : 'Cannot process file' ,
@@ -317,7 +320,7 @@ export class Response extends Macroable implements ResponseContract {
317320 private async streamFileForDownload (
318321 filePath : string ,
319322 generateEtag : boolean ,
320- errorCallback ?: ( ( error : NodeJS . ErrnoException ) => any ) ,
323+ errorCallback ?: ( ( error : NodeJS . ErrnoException ) => [ string , number ? ] ) ,
321324 ) {
322325 try {
323326 const stats = await statFn ( filePath )
@@ -374,9 +377,12 @@ export class Response extends Macroable implements ResponseContract {
374377 return this . streamBody ( createReadStream ( filePath ) , errorCallback )
375378 } catch ( error ) {
376379 if ( typeof ( errorCallback ) === 'function' ) {
377- this . endResponse ( errorCallback ( error ) )
380+ this . endResponse ( ... errorCallback ( error ) )
378381 } else {
379- this . endResponse ( 'Cannot process file' , 404 )
382+ this . endResponse (
383+ error . code === 'ENOENT' ? 'File not found' : 'Cannot process file' ,
384+ error . code === 'ENOENT' ? 404 : 500 ,
385+ )
380386 }
381387 }
382388 }
@@ -726,7 +732,10 @@ export class Response extends Macroable implements ResponseContract {
726732 * }
727733 * ```
728734 */
729- public stream ( body : ResponseStream , errorCallback ?: ( ( error : NodeJS . ErrnoException ) => any ) ) : void {
735+ public stream (
736+ body : ResponseStream ,
737+ errorCallback ?: ( ( error : NodeJS . ErrnoException ) => [ string , number ?] ) ,
738+ ) : void {
730739 if ( typeof ( body . pipe ) !== 'function' || ! body . readable || typeof ( body . read ) !== 'function' ) {
731740 throw new Error ( 'response.stream accepts a readable stream only' )
732741 }
@@ -765,7 +774,7 @@ export class Response extends Macroable implements ResponseContract {
765774 public download (
766775 filePath : string ,
767776 generateEtag : boolean = this . config . etag ,
768- errorCallback ?: ( ( error : NodeJS . ErrnoException ) => any ) ,
777+ errorCallback ?: ( ( error : NodeJS . ErrnoException ) => [ string , number ? ] ) ,
769778 ) : void {
770779 this . lazyBody = {
771780 writer : this . streamFileForDownload ,
@@ -784,7 +793,7 @@ export class Response extends Macroable implements ResponseContract {
784793 name ?: string ,
785794 disposition ?: string ,
786795 generateEtag ?: boolean ,
787- errorCallback ?: ( ( error : NodeJS . ErrnoException ) => any ) ,
796+ errorCallback ?: ( ( error : NodeJS . ErrnoException ) => [ string , number ? ] ) ,
788797 ) {
789798 name = name || filePath
790799 this . header ( 'Content-Disposition' , contentDisposition ( name , { type : disposition } ) )
0 commit comments