fix: Do not write error if response already started.

This commit is contained in:
Ruben Verborgh
2020-12-08 19:50:28 +00:00
parent 1d77a28cd1
commit 907caa1e93
2 changed files with 33 additions and 49 deletions

View File

@@ -28,7 +28,11 @@ export class ExpressHttpServerFactory implements HttpServerFactory {
} catch (error: unknown) {
const errMsg = error instanceof Error ? `${error.name}: ${error.message}\n${error.stack}` : 'Unknown error.';
this.logger.error(errMsg);
response.status(500).contentType('text/plain').send(errMsg);
if (response.headersSent) {
response.end();
} else {
response.status(500).contentType('text/plain').send(errMsg);
}
} finally {
done();
}