Add better detection for write-after-destroy errors on the response

This commit is contained in:
Garrett Mills 2022-03-30 18:33:37 -05:00
parent ca348b2ff6
commit 795adac68b
2 changed files with 7 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@extollo/lib",
"version": "0.9.10",
"version": "0.9.11",
"description": "The framework library that lifts up your code.",
"main": "lib/index.js",
"types": "lib/index.d.ts",

View File

@ -3,6 +3,7 @@ import {ErrorWithContext, HTTPStatus, BehaviorSubject} from '../../util'
import {ServerResponse} from 'http'
import {HTTPCookieJar} from '../kernel/HTTPCookieJar'
import {Readable} from 'stream'
import {Logging} from '../../service/Logging'
/**
* Error thrown when the server tries to re-send headers after they have been sent once.
@ -68,6 +69,10 @@ export class Response {
protected readonly serverResponse: ServerResponse,
) { }
protected get logging(): Logging {
return this.request.make(Logging)
}
/** Get the currently set response status. */
public getStatus(): HTTPStatus {
return this.status
@ -195,7 +200,7 @@ export class Response {
*/
public async write(data: string | Buffer | Uint8Array | Readable): Promise<void> {
return new Promise<void>((res, rej) => {
if ( this.responseEnded ) {
if ( this.responseEnded || this.serverResponse.destroyed ) {
throw new ErrorWithContext('Tried to write to Response after lifecycle ended.')
}