@bymax-one/nest-logger 1.4.11 → 1.4.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -579,6 +579,24 @@ declare class BymaxLoggerModule extends BymaxLoggerModuleBase {
579
579
  * await app.listen(3000)
580
580
  */
581
581
  static useNestLogger(app: INestApplication): void;
582
+ /**
583
+ * Open the request-id correlation scope ahead of the body parser, so a request the parser
584
+ * refuses (malformed JSON, an unsupported content encoding, a body over the limit) still has its
585
+ * `requestId`, and the `x-request-id` response header, where an exception filter reads it.
586
+ *
587
+ * Call once in `main.ts` AFTER creating the app and BEFORE `app.init()` / `app.listen(...)`.
588
+ * It mounts only the scope. `applyAccessLog(app)` and `applyRequestIdMiddleware(consumer)` can
589
+ * be used as well: a second mount of the middleware reuses the scope this one opened.
590
+ *
591
+ * @param app - The Nest application returned by `NestFactory.create()`.
592
+ * @throws Error When `BymaxLoggerModule` was not imported.
593
+ * @example
594
+ * const app = await NestFactory.create(AppModule, { bufferLogs: true })
595
+ * BymaxLoggerModule.useNestLogger(app)
596
+ * BymaxLoggerModule.useRequestContext(app)
597
+ * await app.listen(3000)
598
+ */
599
+ static useRequestContext(app: INestApplication): void;
582
600
  }
583
601
 
584
602
  /**
@@ -1239,6 +1257,22 @@ declare class HttpExceptionFilter implements ExceptionFilter {
1239
1257
  * @param host - The arguments host (switched to HTTP).
1240
1258
  */
1241
1259
  catch(exception: unknown, host: ArgumentsHost): void;
1260
+ /**
1261
+ * Log an exposed client error as handled and answer it with its own status and message.
1262
+ *
1263
+ * @param clientError - The status and message the error exposes.
1264
+ * @param res - The response to write.
1265
+ * @param request - The request facts every entry carries.
1266
+ */
1267
+ private answerClientError;
1268
+ /**
1269
+ * Log any other non-`HttpException` as unhandled and answer it with the fixed 500 body.
1270
+ *
1271
+ * @param exception - The thrown value.
1272
+ * @param res - The response to write.
1273
+ * @param request - The request facts every entry carries.
1274
+ */
1275
+ private answerUnhandled;
1242
1276
  }
1243
1277
 
1244
1278
  /**
@@ -1300,8 +1334,8 @@ declare class HttpLoggingInterceptor implements NestInterceptor {
1300
1334
  private logSuccess;
1301
1335
  /**
1302
1336
  * Log a thrown completion: SERVER_ERROR (error level, with stack) for 5xx,
1303
- * CLIENT_ERROR (warn level) for an `HttpException` below 500. A non-`HttpException`
1304
- * always maps to 500, so it is reported as a server error.
1337
+ * CLIENT_ERROR (warn level) for an `HttpException` below 500 or an exposed `http-errors`
1338
+ * client error. Any other non-`HttpException` maps to 500, so it is reported as a server error.
1305
1339
  *
1306
1340
  * @param err - The thrown value (anything).
1307
1341
  * @param method - The HTTP method.
@@ -1310,6 +1344,16 @@ declare class HttpLoggingInterceptor implements NestInterceptor {
1310
1344
  * @param duration - The elapsed time in milliseconds.
1311
1345
  */
1312
1346
  private logError;
1347
+ /**
1348
+ * Log an exposed `http-errors` client error as CLIENT_ERROR at warn level.
1349
+ *
1350
+ * @param clientError - The status and message the error exposes.
1351
+ * @param method - The HTTP method.
1352
+ * @param url - The normalized request URL.
1353
+ * @param userId - The acting user id, when known.
1354
+ * @param duration - The elapsed time in milliseconds.
1355
+ */
1356
+ private logClientError;
1313
1357
  }
1314
1358
 
1315
1359
  /**
@@ -579,6 +579,24 @@ declare class BymaxLoggerModule extends BymaxLoggerModuleBase {
579
579
  * await app.listen(3000)
580
580
  */
581
581
  static useNestLogger(app: INestApplication): void;
582
+ /**
583
+ * Open the request-id correlation scope ahead of the body parser, so a request the parser
584
+ * refuses (malformed JSON, an unsupported content encoding, a body over the limit) still has its
585
+ * `requestId`, and the `x-request-id` response header, where an exception filter reads it.
586
+ *
587
+ * Call once in `main.ts` AFTER creating the app and BEFORE `app.init()` / `app.listen(...)`.
588
+ * It mounts only the scope. `applyAccessLog(app)` and `applyRequestIdMiddleware(consumer)` can
589
+ * be used as well: a second mount of the middleware reuses the scope this one opened.
590
+ *
591
+ * @param app - The Nest application returned by `NestFactory.create()`.
592
+ * @throws Error When `BymaxLoggerModule` was not imported.
593
+ * @example
594
+ * const app = await NestFactory.create(AppModule, { bufferLogs: true })
595
+ * BymaxLoggerModule.useNestLogger(app)
596
+ * BymaxLoggerModule.useRequestContext(app)
597
+ * await app.listen(3000)
598
+ */
599
+ static useRequestContext(app: INestApplication): void;
582
600
  }
583
601
 
584
602
  /**
@@ -1239,6 +1257,22 @@ declare class HttpExceptionFilter implements ExceptionFilter {
1239
1257
  * @param host - The arguments host (switched to HTTP).
1240
1258
  */
1241
1259
  catch(exception: unknown, host: ArgumentsHost): void;
1260
+ /**
1261
+ * Log an exposed client error as handled and answer it with its own status and message.
1262
+ *
1263
+ * @param clientError - The status and message the error exposes.
1264
+ * @param res - The response to write.
1265
+ * @param request - The request facts every entry carries.
1266
+ */
1267
+ private answerClientError;
1268
+ /**
1269
+ * Log any other non-`HttpException` as unhandled and answer it with the fixed 500 body.
1270
+ *
1271
+ * @param exception - The thrown value.
1272
+ * @param res - The response to write.
1273
+ * @param request - The request facts every entry carries.
1274
+ */
1275
+ private answerUnhandled;
1242
1276
  }
1243
1277
 
1244
1278
  /**
@@ -1300,8 +1334,8 @@ declare class HttpLoggingInterceptor implements NestInterceptor {
1300
1334
  private logSuccess;
1301
1335
  /**
1302
1336
  * Log a thrown completion: SERVER_ERROR (error level, with stack) for 5xx,
1303
- * CLIENT_ERROR (warn level) for an `HttpException` below 500. A non-`HttpException`
1304
- * always maps to 500, so it is reported as a server error.
1337
+ * CLIENT_ERROR (warn level) for an `HttpException` below 500 or an exposed `http-errors`
1338
+ * client error. Any other non-`HttpException` maps to 500, so it is reported as a server error.
1305
1339
  *
1306
1340
  * @param err - The thrown value (anything).
1307
1341
  * @param method - The HTTP method.
@@ -1310,6 +1344,16 @@ declare class HttpLoggingInterceptor implements NestInterceptor {
1310
1344
  * @param duration - The elapsed time in milliseconds.
1311
1345
  */
1312
1346
  private logError;
1347
+ /**
1348
+ * Log an exposed `http-errors` client error as CLIENT_ERROR at warn level.
1349
+ *
1350
+ * @param clientError - The status and message the error exposes.
1351
+ * @param method - The HTTP method.
1352
+ * @param url - The normalized request URL.
1353
+ * @param userId - The acting user id, when known.
1354
+ * @param duration - The elapsed time in milliseconds.
1355
+ */
1356
+ private logClientError;
1313
1357
  }
1314
1358
 
1315
1359
  /**