@@ -70,13 +70,13 @@ export default class ErrorHandler {
7070 // This handler serves as Fastify & Tailor handler.
7171 // While Fastify will pass it's own Reply object
7272 // Tailor passes http.ServerResponse from Node core
73- let nres : ServerResponse ;
73+ let rawResponse : ServerResponse ;
7474 if ( isFastifyReply ( res ) ) {
75- nres = res . res ;
75+ rawResponse = res . raw ;
7676 // Claim full responsibility of the low-level response from Fastify
77- res . sent = true ;
77+ res . hijack ( ) ;
7878 } else {
79- nres = res as ServerResponse ;
79+ rawResponse = res as ServerResponse ;
8080 }
8181
8282 try {
@@ -87,24 +87,24 @@ export default class ErrorHandler {
8787 let data = await this . registryService . getTemplate ( '500' , { locale, forDomain : currentDomain } ) ;
8888 const content = data . data . content . replace ( '%ERRORID%' , `Error ID: ${ errorId } ` ) ;
8989
90- this . ensureInternalErrorHeaders ( nres , StatusCodes . INTERNAL_SERVER_ERROR ) ;
91- nres . write ( content ) ;
92- nres . end ( ) ;
90+ this . ensureInternalErrorHeaders ( rawResponse , StatusCodes . INTERNAL_SERVER_ERROR ) ;
91+ rawResponse . write ( content ) ;
92+ rawResponse . end ( ) ;
9393 } catch ( causeErr ) {
9494 const handlingError = new ErrorHandlingError ( {
9595 message : 'Additional error in error handling' ,
9696 cause : causeErr as Error ,
9797 data : { errorId, originalError : safeJsonStringify ( err ) } ,
9898 } ) ;
9999 this . logger . error ( handlingError ) ;
100- this . writeStaticError ( nres ) ;
100+ this . writeStaticError ( rawResponse ) ;
101101 }
102102 }
103103
104104 async handleClientError ( reply : ServerResponseFastifyReply , error : Error , statusCode ?: number ) : Promise < void > {
105105 this . logger . warn ( error ) ;
106- reply . sent = true ;
107- this . writeStaticError ( reply . res ! , statusCode ) ;
106+ reply . hijack ( ) ;
107+ this . writeStaticError ( reply . raw , statusCode ) ;
108108 }
109109
110110 private ensureInternalErrorHeaders ( nres : ServerResponse , statusCode : number ) : void {
0 commit comments