@sdflc/backend-helpers 1.0.66 → 1.0.68
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.
package/build/BaseCore.js
CHANGED
|
@@ -145,7 +145,7 @@ class BaseCore {
|
|
|
145
145
|
}
|
|
146
146
|
runAction(opt) {
|
|
147
147
|
return __awaiter(this, void 0, void 0, function* () {
|
|
148
|
-
const { args, validate, doAuth, action, hasTransaction, doingWhat, onException, shouldLogArgs } = opt || {};
|
|
148
|
+
const { args, validate, doAuth, action, hasTransaction, doingWhat, onException, shouldLogArgs, requireSpace } = opt || {};
|
|
149
149
|
// If we process action with the same requestId as requestId passed to the constructor it means
|
|
150
150
|
// we are processing the same request from FE and can skip some of the operations like transactions and etc
|
|
151
151
|
const sameRequest = !!this.config.context.requestId && (args === null || args === void 0 ? void 0 : args.requestId) === this.config.context.requestId;
|
|
@@ -185,15 +185,21 @@ class BaseCore {
|
|
|
185
185
|
const [authResult, errMsg] = yield this.authenticate(opt, actionOpt);
|
|
186
186
|
this.measureTool.addCheckpoint('Authenticate request: end');
|
|
187
187
|
if (!authResult) {
|
|
188
|
-
|
|
188
|
+
const result = new api_helpers_1.OpResult({ code: api_helpers_1.OP_RESULT_CODES.UNAUTHORIZED }).addError('', errMsg);
|
|
189
|
+
this.logger.error(`The ${step} requires authentication and it has failed:`, errMsg);
|
|
190
|
+
yield this.checkResult({ hasTransaction, result, sameRequest, doingWhat });
|
|
191
|
+
return result;
|
|
189
192
|
}
|
|
190
193
|
}
|
|
191
|
-
else {
|
|
194
|
+
else if (requireSpace == null || requireSpace === true) {
|
|
192
195
|
this.measureTool.addCheckpoint('Find space: start');
|
|
193
196
|
const [spaceResult, errMsg] = yield this.findSpace();
|
|
194
197
|
this.measureTool.addCheckpoint('Find space: end');
|
|
195
198
|
if (spaceResult !== true) {
|
|
196
|
-
|
|
199
|
+
const result = new api_helpers_1.OpResult({ code: api_helpers_1.OP_RESULT_CODES.UNAUTHORIZED }).addError('', errMsg);
|
|
200
|
+
this.logger.error(`The ${step} requires a space and it has failed:`, errMsg);
|
|
201
|
+
yield this.checkResult({ hasTransaction, result, sameRequest, doingWhat });
|
|
202
|
+
return result;
|
|
197
203
|
}
|
|
198
204
|
}
|
|
199
205
|
}
|
|
@@ -228,7 +234,9 @@ class BaseCore {
|
|
|
228
234
|
return result;
|
|
229
235
|
}
|
|
230
236
|
catch (ex) {
|
|
237
|
+
this.logger.error(`An exception has occurred on ${step}:`, ex);
|
|
231
238
|
if (!sameRequest && hasTransaction) {
|
|
239
|
+
this.logger.debug(`Rolling back DB transaction on ${step} due to an excaption`);
|
|
232
240
|
yield this.getDb().rollbackTransaction();
|
|
233
241
|
}
|
|
234
242
|
let errMessage = '';
|
|
@@ -239,7 +247,7 @@ class BaseCore {
|
|
|
239
247
|
}
|
|
240
248
|
}
|
|
241
249
|
catch (ex2) {
|
|
242
|
-
this.logger.
|
|
250
|
+
this.logger.error(`An exception has occured when handling exception:`, ex2);
|
|
243
251
|
}
|
|
244
252
|
if (!errMessage) {
|
|
245
253
|
errMessage = doingWhat;
|
package/package.json
CHANGED