badmfck-api-server 4.1.9 → 4.1.11

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.09";
101
+ version = "4.1.11";
102
102
  options;
103
103
  monitor = null;
104
104
  started = new Date();
@@ -481,7 +481,8 @@ class APIService extends BaseService_1.BaseService {
481
481
  if (this.options.appVersion)
482
482
  data.version = this.options.appVersion;
483
483
  if (res.socket?.destroyed || res.writableEnded || res.headersSent || (res.destroyed !== undefined && res.destroyed)) {
484
- (0, LogService_1.logAPI)("Connection already closed, can't send response for: " + data.endpoint);
484
+ if (!data.ignoreHttpLogging)
485
+ (0, LogService_1.logAPI)("Connection already closed, can't send response for: " + data.endpoint);
485
486
  }
486
487
  else {
487
488
  try {
@@ -489,7 +490,8 @@ class APIService extends BaseService_1.BaseService {
489
490
  const normalizedFile = process.platform === "win32" ? data.file : data.file.replaceAll("\\", "/");
490
491
  const filePath = path_1.default.isAbsolute(normalizedFile) ? normalizedFile : path_1.default.resolve(normalizedFile);
491
492
  const onSendFileError = (err) => {
492
- (0, LogService_1.logError)("Can't send file: " + filePath);
493
+ if (!data.ignoreHttpLogging)
494
+ (0, LogService_1.logError)("Can't send file: " + filePath);
493
495
  if (!res.headersSent && !res.writableEnded) {
494
496
  res.status(500).send({ error: DefaultErrors_1.default.CANT_SEND_FILE, data: null });
495
497
  return;
@@ -520,7 +522,8 @@ class APIService extends BaseService_1.BaseService {
520
522
  }
521
523
  if (data.redirect) {
522
524
  res.redirect(data.redirect);
523
- (0, LogService_1.logAPI)("redirect: " + data.redirect);
525
+ if (!data.ignoreHttpLogging)
526
+ (0, LogService_1.logAPI)("redirect: " + data.redirect);
524
527
  }
525
528
  else {
526
529
  if (data.headers) {
@@ -533,11 +536,13 @@ class APIService extends BaseService_1.BaseService {
533
536
  res.statusCode = data.httpStatus ?? 200;
534
537
  if (data.rawResponse) {
535
538
  res.send(data.data);
536
- (0, LogService_1.logAPI)(this.checkDataLength(data));
539
+ if (!data.ignoreHttpLogging)
540
+ (0, LogService_1.logAPI)(this.checkDataLength(data));
537
541
  }
538
542
  else {
539
543
  res.send(data);
540
- (0, LogService_1.logAPI)(this.checkDataLength(data));
544
+ if (!data.ignoreHttpLogging)
545
+ (0, LogService_1.logAPI)(this.checkDataLength(data));
541
546
  }
542
547
  }
543
548
  }
@@ -550,7 +550,7 @@ class MysqlAdapter {
550
550
  (0, LogService_1.logError)("Connection looks dead, recreating pool 1");
551
551
  this.recreatePool();
552
552
  }
553
- if (trx)
553
+ if (trx && !error.isDuplicateError)
554
554
  this.storeTransactionAsProblem(trx, "error:" + error.errno);
555
555
  if (request.throwable)
556
556
  throw { ...DefaultErrors_1.default.DB_ERROR, details: error.message, stack: error };
@@ -799,23 +799,31 @@ class MysqlAdapter {
799
799
  const yyymmdd = new Date().toISOString().substring(0, 10).replaceAll("-", "");
800
800
  const date = new Date();
801
801
  const file = path_1.default.resolve(this.options.transactionFailReportDir, yyymmdd + ".json");
802
- if (this.failReportFileStream) {
803
- if (this.failReportFileStreamName !== file) {
802
+ if (this.failReportFileStream && this.failReportFileStreamName !== file) {
803
+ try {
804
804
  this.failReportFileStream.end();
805
- this.failReportFileStream = null;
806
805
  }
807
- }
808
- if (this.failReportFileStreamName) {
809
- this.failReportFileStream = fs_1.default.createWriteStream(file, { flags: 'a' });
810
- this.failReportFileStreamName = file;
806
+ catch { }
807
+ this.failReportFileStream = null;
808
+ this.failReportFileStreamName = null;
811
809
  }
812
810
  if (this.options.debug)
813
811
  (0, LogService_1.logDB)("Store transaction fail report: ", file, trx.queries, message);
814
- if (!this.failReportFileStream)
815
- this.failReportFileStream = fs_1.default.createWriteStream(file, { flags: 'a' });
812
+ if (!this.failReportFileStream) {
813
+ const stream = fs_1.default.createWriteStream(file, { flags: 'a' });
814
+ stream.on('error', (err) => {
815
+ (0, LogService_1.logCrit)("MysqlAdapter", "Transaction fail report stream error: " + err.message);
816
+ if (this.failReportFileStream === stream) {
817
+ this.failReportFileStream = null;
818
+ this.failReportFileStreamName = null;
819
+ }
820
+ });
821
+ this.failReportFileStream = stream;
822
+ this.failReportFileStreamName = file;
823
+ }
816
824
  this.failReportFileStream.write(JSON.stringify({ queries: trx.queries, time: trx.timestamp, date, message }) + "\n}EOB{\n", err => {
817
825
  if (err)
818
- (0, LogService_1.logCrit)("MysqlAdapter", "Can't write to transaction fail report file");
826
+ (0, LogService_1.logCrit)("MysqlAdapter", "Can't write to transaction fail report file: " + err.message);
819
827
  else
820
828
  (0, LogService_1.logDB)("MysqlAdapter", "Transaction fail report stored");
821
829
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "4.1.09",
3
+ "version": "4.1.11",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",