badmfck-api-server 4.1.10 → 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();
@@ -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.10",
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",