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

orm-types
Garrett Mills 2 years ago
parent ca348b2ff6
commit 795adac68b

@ -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",

@ -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.')
}

Loading…
Cancel
Save