diff --git a/src/app.ts b/src/app.ts index 0ad338e7..4ff3536f 100644 --- a/src/app.ts +++ b/src/app.ts @@ -14,8 +14,8 @@ * along with this program. If not, see . */ import { - SCInternalServerErrorResponse, SCNotFoundErrorResponse, + SCRequestBodyTooLargeErrorResponse, SCSyntaxErrorResponse, SCUnsupportedMediaTypeErrorResponse, } from '@openstapps/core'; @@ -47,11 +47,14 @@ async function configureApp() { // only accept json as content type for all requests app.use((req, res, next) => { - // Get the content type + // get the content type let contentType = ''; + // the content type can be string, string[] or undefined if (typeof req.headers['Content-Type'] === 'string') { + // weird type definitions require an explicit cast contentType = req.headers['Content-Type'] as string; } else if (typeof req.headers['content-type'] === 'string') { + // weird type definitions require no cast here though... contentType = req.headers['content-type']; } @@ -70,7 +73,7 @@ async function configureApp() { if (bodySize > 512 * 1024) { req.off('data', chunkGatherer); req.off('end', endCallback); - const err = new SCInternalServerErrorResponse(new Error('Request body is too large!'), isTestEnvironment); + const err = new SCRequestBodyTooLargeErrorResponse(isTestEnvironment); res.status(err.statusCode); res.json(err); return; diff --git a/src/cli.ts b/src/cli.ts index e62f3f3e..ff42840c 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -86,12 +86,8 @@ function onError(error: Error | any) { */ function onListening() { const addr = server.address(); - if (addr === null) { - logger.warn('Listening on null'); - } else { - const bind = typeof addr === 'string' - ? 'pipe ' + addr - : 'port ' + addr.port; - logger.ok('Listening on ' + bind); - } + const bind = typeof addr === 'string' + ? 'pipe ' + addr + : 'port ' + addr.port; + logger.ok('Listening on ' + bind); }