Add better detection for write-after-destroy errors on the response
This commit is contained in:
parent
ca348b2ff6
commit
795adac68b
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@extollo/lib",
|
"name": "@extollo/lib",
|
||||||
"version": "0.9.10",
|
"version": "0.9.11",
|
||||||
"description": "The framework library that lifts up your code.",
|
"description": "The framework library that lifts up your code.",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"types": "lib/index.d.ts",
|
"types": "lib/index.d.ts",
|
||||||
|
@ -3,6 +3,7 @@ import {ErrorWithContext, HTTPStatus, BehaviorSubject} from '../../util'
|
|||||||
import {ServerResponse} from 'http'
|
import {ServerResponse} from 'http'
|
||||||
import {HTTPCookieJar} from '../kernel/HTTPCookieJar'
|
import {HTTPCookieJar} from '../kernel/HTTPCookieJar'
|
||||||
import {Readable} from 'stream'
|
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.
|
* 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 readonly serverResponse: ServerResponse,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
|
protected get logging(): Logging {
|
||||||
|
return this.request.make(Logging)
|
||||||
|
}
|
||||||
|
|
||||||
/** Get the currently set response status. */
|
/** Get the currently set response status. */
|
||||||
public getStatus(): HTTPStatus {
|
public getStatus(): HTTPStatus {
|
||||||
return this.status
|
return this.status
|
||||||
@ -195,7 +200,7 @@ export class Response {
|
|||||||
*/
|
*/
|
||||||
public async write(data: string | Buffer | Uint8Array | Readable): Promise<void> {
|
public async write(data: string | Buffer | Uint8Array | Readable): Promise<void> {
|
||||||
return new Promise<void>((res, rej) => {
|
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.')
|
throw new ErrorWithContext('Tried to write to Response after lifecycle ended.')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user