badmfck-api-server 4.1.12 → 4.1.14

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.
@@ -98,7 +98,7 @@ async function Initializer(services) {
98
98
  }
99
99
  exports.Initializer = Initializer;
100
100
  class APIService extends BaseService_1.BaseService {
101
- version = "4.1.12";
101
+ version = "4.1.14";
102
102
  options;
103
103
  monitor = null;
104
104
  started = new Date();
@@ -331,6 +331,10 @@ class APIService extends BaseService_1.BaseService {
331
331
  respond({ error: { ...DefaultErrors_1.default.DB_ERROR, details: e.message } });
332
332
  return;
333
333
  }
334
+ if (DefaultErrors_1.ErrorUtils.isError(e)) {
335
+ respond({ error: e });
336
+ return;
337
+ }
334
338
  respond({ error: { code: 10002, message: "Internal server error!", stack: stack, details: details }, data: null, httpStatus: 500 });
335
339
  return;
336
340
  }
@@ -456,14 +460,16 @@ class APIService extends BaseService_1.BaseService {
456
460
  nextLogID = 0;
457
461
  }
458
462
  async sendResponse(ref, res, data, requestTime, endpoint, req) {
463
+ const ignoreHttpLogging = data.ignoreHttpLogging ?? false;
464
+ delete data.ignoreHttpLogging;
459
465
  if (data.blockResponse) {
460
- if (!data.ignoreHttpLogging)
466
+ if (!ignoreHttpLogging)
461
467
  (0, LogService_1.logAPI)("Response blocked");
462
- if (req && !data.ignoreHttpLogging)
468
+ if (req && !ignoreHttpLogging)
463
469
  this.addNetlog(data, req, requestTime, 0);
464
470
  return;
465
471
  }
466
- if (!data.ignoreHttpLogging)
472
+ if (!ignoreHttpLogging)
467
473
  MonitorService_1.S_STAT_REGISTRATE_REQUEST.invoke({ ...data, endpoint: data.endpoint ?? endpoint });
468
474
  if (this.options.postproducer) {
469
475
  try {
@@ -481,7 +487,7 @@ class APIService extends BaseService_1.BaseService {
481
487
  if (this.options.appVersion)
482
488
  data.version = this.options.appVersion;
483
489
  if (res.socket?.destroyed || res.writableEnded || res.headersSent || (res.destroyed !== undefined && res.destroyed)) {
484
- if (!data.ignoreHttpLogging)
490
+ if (!ignoreHttpLogging)
485
491
  (0, LogService_1.logAPI)("Connection already closed, can't send response for: " + data.endpoint);
486
492
  }
487
493
  else {
@@ -490,7 +496,7 @@ class APIService extends BaseService_1.BaseService {
490
496
  const normalizedFile = process.platform === "win32" ? data.file : data.file.replaceAll("\\", "/");
491
497
  const filePath = path_1.default.isAbsolute(normalizedFile) ? normalizedFile : path_1.default.resolve(normalizedFile);
492
498
  const onSendFileError = (err) => {
493
- if (!data.ignoreHttpLogging)
499
+ if (!ignoreHttpLogging)
494
500
  (0, LogService_1.logError)("Can't send file: " + filePath);
495
501
  if (!res.headersSent && !res.writableEnded) {
496
502
  res.status(500).send({ error: DefaultErrors_1.default.CANT_SEND_FILE, data: null });
@@ -536,12 +542,12 @@ class APIService extends BaseService_1.BaseService {
536
542
  res.statusCode = data.httpStatus ?? 200;
537
543
  if (data.rawResponse) {
538
544
  res.send(data.data);
539
- if (!data.ignoreHttpLogging)
545
+ if (!ignoreHttpLogging)
540
546
  (0, LogService_1.logAPI)(this.checkDataLength(data));
541
547
  }
542
548
  else {
543
549
  res.send(data);
544
- if (!data.ignoreHttpLogging)
550
+ if (!ignoreHttpLogging)
545
551
  (0, LogService_1.logAPI)(this.checkDataLength(data));
546
552
  }
547
553
  }
@@ -550,7 +556,7 @@ class APIService extends BaseService_1.BaseService {
550
556
  console.error(e);
551
557
  }
552
558
  }
553
- if (req && !data.ignoreHttpLogging)
559
+ if (req && !ignoreHttpLogging)
554
560
  this.addNetlog(data, req, requestTime, 0);
555
561
  }
556
562
  checkDataLength(data, result, lvl) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "4.1.12",
3
+ "version": "4.1.14",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",