badmfck-api-server 4.1.11 → 4.1.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.
|
@@ -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.
|
|
101
|
+
version = "4.1.13";
|
|
102
102
|
options;
|
|
103
103
|
monitor = null;
|
|
104
104
|
started = new Date();
|
|
@@ -456,14 +456,16 @@ class APIService extends BaseService_1.BaseService {
|
|
|
456
456
|
nextLogID = 0;
|
|
457
457
|
}
|
|
458
458
|
async sendResponse(ref, res, data, requestTime, endpoint, req) {
|
|
459
|
+
const ignoreHttpLogging = data.ignoreHttpLogging ?? false;
|
|
460
|
+
delete data.ignoreHttpLogging;
|
|
459
461
|
if (data.blockResponse) {
|
|
460
|
-
if (!
|
|
462
|
+
if (!ignoreHttpLogging)
|
|
461
463
|
(0, LogService_1.logAPI)("Response blocked");
|
|
462
|
-
if (req && !
|
|
464
|
+
if (req && !ignoreHttpLogging)
|
|
463
465
|
this.addNetlog(data, req, requestTime, 0);
|
|
464
466
|
return;
|
|
465
467
|
}
|
|
466
|
-
if (!
|
|
468
|
+
if (!ignoreHttpLogging)
|
|
467
469
|
MonitorService_1.S_STAT_REGISTRATE_REQUEST.invoke({ ...data, endpoint: data.endpoint ?? endpoint });
|
|
468
470
|
if (this.options.postproducer) {
|
|
469
471
|
try {
|
|
@@ -481,7 +483,7 @@ class APIService extends BaseService_1.BaseService {
|
|
|
481
483
|
if (this.options.appVersion)
|
|
482
484
|
data.version = this.options.appVersion;
|
|
483
485
|
if (res.socket?.destroyed || res.writableEnded || res.headersSent || (res.destroyed !== undefined && res.destroyed)) {
|
|
484
|
-
if (!
|
|
486
|
+
if (!ignoreHttpLogging)
|
|
485
487
|
(0, LogService_1.logAPI)("Connection already closed, can't send response for: " + data.endpoint);
|
|
486
488
|
}
|
|
487
489
|
else {
|
|
@@ -490,7 +492,7 @@ class APIService extends BaseService_1.BaseService {
|
|
|
490
492
|
const normalizedFile = process.platform === "win32" ? data.file : data.file.replaceAll("\\", "/");
|
|
491
493
|
const filePath = path_1.default.isAbsolute(normalizedFile) ? normalizedFile : path_1.default.resolve(normalizedFile);
|
|
492
494
|
const onSendFileError = (err) => {
|
|
493
|
-
if (!
|
|
495
|
+
if (!ignoreHttpLogging)
|
|
494
496
|
(0, LogService_1.logError)("Can't send file: " + filePath);
|
|
495
497
|
if (!res.headersSent && !res.writableEnded) {
|
|
496
498
|
res.status(500).send({ error: DefaultErrors_1.default.CANT_SEND_FILE, data: null });
|
|
@@ -536,12 +538,12 @@ class APIService extends BaseService_1.BaseService {
|
|
|
536
538
|
res.statusCode = data.httpStatus ?? 200;
|
|
537
539
|
if (data.rawResponse) {
|
|
538
540
|
res.send(data.data);
|
|
539
|
-
if (!
|
|
541
|
+
if (!ignoreHttpLogging)
|
|
540
542
|
(0, LogService_1.logAPI)(this.checkDataLength(data));
|
|
541
543
|
}
|
|
542
544
|
else {
|
|
543
545
|
res.send(data);
|
|
544
|
-
if (!
|
|
546
|
+
if (!ignoreHttpLogging)
|
|
545
547
|
(0, LogService_1.logAPI)(this.checkDataLength(data));
|
|
546
548
|
}
|
|
547
549
|
}
|
|
@@ -550,7 +552,7 @@ class APIService extends BaseService_1.BaseService {
|
|
|
550
552
|
console.error(e);
|
|
551
553
|
}
|
|
552
554
|
}
|
|
553
|
-
if (req && !
|
|
555
|
+
if (req && !ignoreHttpLogging)
|
|
554
556
|
this.addNetlog(data, req, requestTime, 0);
|
|
555
557
|
}
|
|
556
558
|
checkDataLength(data, result, lvl) {
|
|
@@ -552,8 +552,10 @@ class MysqlAdapter {
|
|
|
552
552
|
}
|
|
553
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,
|
|
@@ -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 };
|