fix: Integrate wrapStreamError to prevent uncaught errors

This commit is contained in:
Joachim Van Herwegen
2020-11-17 13:06:29 +01:00
parent 1a30b51461
commit e4183333fd
24 changed files with 112 additions and 108 deletions

View File

@@ -3,6 +3,7 @@ import cors from 'cors';
import type { Express } from 'express';
import express from 'express';
import { getLoggerFor } from '../logging/LogUtil';
import { guardStream } from '../util/GuardedStream';
import type { HttpHandler } from './HttpHandler';
import type { HttpServerFactory } from './HttpServerFactory';
@@ -40,7 +41,7 @@ export class ExpressHttpServerFactory implements HttpServerFactory {
app.use(async(request, response, done): Promise<void> => {
try {
this.logger.info(`Received request for ${request.url}`);
await this.handler.handleSafe({ request, response });
await this.handler.handleSafe({ request: guardStream(request), response });
} catch (error: unknown) {
const errMsg = error instanceof Error ? `${error.name}: ${error.message}\n${error.stack}` : 'Unknown error.';
this.logger.error(errMsg);

View File

@@ -1,6 +1,7 @@
import type { IncomingMessage } from 'http';
import type { Guarded } from '../util/GuardedStream';
/**
* An incoming HTTP request;
*/
export type HttpRequest = IncomingMessage;
export type HttpRequest = Guarded<IncomingMessage>;