badmfck-api-server 4.1.10 → 4.1.12
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.
|
@@ -550,10 +550,12 @@ 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
|
-
if (request.throwable)
|
|
556
|
-
|
|
555
|
+
if (request.throwable) {
|
|
556
|
+
const base = error.isDuplicateError ? DefaultErrors_1.default.DB_DUPLICATE_ERROR : DefaultErrors_1.default.DB_ERROR;
|
|
557
|
+
throw { ...base, details: error.message, stack: error };
|
|
558
|
+
}
|
|
557
559
|
return {
|
|
558
560
|
data: null,
|
|
559
561
|
error: error,
|
|
@@ -799,23 +801,31 @@ class MysqlAdapter {
|
|
|
799
801
|
const yyymmdd = new Date().toISOString().substring(0, 10).replaceAll("-", "");
|
|
800
802
|
const date = new Date();
|
|
801
803
|
const file = path_1.default.resolve(this.options.transactionFailReportDir, yyymmdd + ".json");
|
|
802
|
-
if (this.failReportFileStream) {
|
|
803
|
-
|
|
804
|
+
if (this.failReportFileStream && this.failReportFileStreamName !== file) {
|
|
805
|
+
try {
|
|
804
806
|
this.failReportFileStream.end();
|
|
805
|
-
this.failReportFileStream = null;
|
|
806
807
|
}
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
this.
|
|
810
|
-
this.failReportFileStreamName = file;
|
|
808
|
+
catch { }
|
|
809
|
+
this.failReportFileStream = null;
|
|
810
|
+
this.failReportFileStreamName = null;
|
|
811
811
|
}
|
|
812
812
|
if (this.options.debug)
|
|
813
813
|
(0, LogService_1.logDB)("Store transaction fail report: ", file, trx.queries, message);
|
|
814
|
-
if (!this.failReportFileStream)
|
|
815
|
-
|
|
814
|
+
if (!this.failReportFileStream) {
|
|
815
|
+
const stream = fs_1.default.createWriteStream(file, { flags: 'a' });
|
|
816
|
+
stream.on('error', (err) => {
|
|
817
|
+
(0, LogService_1.logCrit)("MysqlAdapter", "Transaction fail report stream error: " + err.message);
|
|
818
|
+
if (this.failReportFileStream === stream) {
|
|
819
|
+
this.failReportFileStream = null;
|
|
820
|
+
this.failReportFileStreamName = null;
|
|
821
|
+
}
|
|
822
|
+
});
|
|
823
|
+
this.failReportFileStream = stream;
|
|
824
|
+
this.failReportFileStreamName = file;
|
|
825
|
+
}
|
|
816
826
|
this.failReportFileStream.write(JSON.stringify({ queries: trx.queries, time: trx.timestamp, date, message }) + "\n}EOB{\n", err => {
|
|
817
827
|
if (err)
|
|
818
|
-
(0, LogService_1.logCrit)("MysqlAdapter", "Can't write to transaction fail report file");
|
|
828
|
+
(0, LogService_1.logCrit)("MysqlAdapter", "Can't write to transaction fail report file: " + err.message);
|
|
819
829
|
else
|
|
820
830
|
(0, LogService_1.logDB)("MysqlAdapter", "Transaction fail report stored");
|
|
821
831
|
});
|
|
@@ -15,6 +15,7 @@ class DefaultErrors {
|
|
|
15
15
|
static TIMEOUT = { code: 9, message: "Timeout", httpStatus: 408 };
|
|
16
16
|
static METHOD_NOT_ALLOWED = { code: 10, message: "Method not allowed", httpStatus: 405 };
|
|
17
17
|
static DB_ERROR = { code: 11, message: "DB error", httpStatus: 500 };
|
|
18
|
+
static DB_DUPLICATE_ERROR = { code: 28, message: "DB duplicate entry", httpStatus: 409 };
|
|
18
19
|
static FORBIDDEN = { code: 12, message: "Forbidden", httpStatus: 403 };
|
|
19
20
|
static NOT_FOUND = { code: 13, message: "Not found", httpStatus: 404 };
|
|
20
21
|
static INTERNAL_SERVER_ERROR = { code: 14, message: "Internal server error.", httpStatus: 500 };
|