@stemy/backend 3.5.9 → 3.5.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.
@@ -1270,6 +1270,20 @@
1270
1270
  return arr.reduce(function (flat, toFlatten) {
1271
1271
  return flat.concat(isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
1272
1272
  }, []);
1273
+ }
1274
+ function wrapError(e, message, httpCode) {
1275
+ if (httpCode === void 0) { httpCode = 500; }
1276
+ if (e instanceof axios.AxiosError) {
1277
+ e.message = message;
1278
+ return e;
1279
+ }
1280
+ return new routingControllers.HttpError(httpCode, message + ": " + e);
1281
+ }
1282
+ function prepareUrl(ending) {
1283
+ if (ending === void 0) { ending = ""; }
1284
+ return function (url) {
1285
+ return url ? "" + url.replace(/\/+$/, "") + ending : ending;
1286
+ };
1273
1287
  }
1274
1288
 
1275
1289
  var __decorate$B = (this && this.__decorate) || function (decorators, target, key, desc) {
@@ -5499,15 +5513,22 @@
5499
5513
  configurable: true
5500
5514
  });
5501
5515
  ErrorHandlerMiddleware.prototype.error = function (error, req, res, next) {
5516
+ var _a;
5502
5517
  return __awaiter$6(this, void 0, void 0, function () {
5503
5518
  var result;
5504
- return __generator(this, function (_a) {
5505
- switch (_a.label) {
5519
+ return __generator(this, function (_b) {
5520
+ switch (_b.label) {
5506
5521
  case 0: return [4 /*yield*/, this.getResult(error, req, res)];
5507
5522
  case 1:
5508
- result = _a.sent();
5523
+ result = _b.sent();
5509
5524
  if (this.isDev) {
5510
- console.log("ERROR", result, res.statusCode);
5525
+ if (error instanceof axios.AxiosError) {
5526
+ console.log("Axios error:", result);
5527
+ console.log(error.config.data);
5528
+ }
5529
+ else {
5530
+ console.log(((_a = error.constructor) === null || _a === void 0 ? void 0 : _a.name) || "Error", result, res.statusCode);
5531
+ }
5511
5532
  }
5512
5533
  res.json(result);
5513
5534
  return [2 /*return*/];
@@ -5517,38 +5538,43 @@
5517
5538
  };
5518
5539
  ErrorHandlerMiddleware.prototype.getResult = function (error, req, res) {
5519
5540
  return __awaiter$6(this, void 0, void 0, function () {
5520
- var result, _a, _b, _c;
5521
- return __generator(this, function (_d) {
5522
- switch (_d.label) {
5541
+ var result, _b, _c, _d;
5542
+ return __generator(this, function (_e) {
5543
+ switch (_e.label) {
5523
5544
  case 0:
5524
5545
  result = {};
5546
+ if (error instanceof axios.AxiosError) {
5547
+ res.status(error.response.status);
5548
+ result.message = error.message;
5549
+ result.error = error.response.data;
5550
+ result.headers = error.response.headers;
5551
+ result.url = "" + error.config.baseURL + error.config.url;
5552
+ return [2 /*return*/, result];
5553
+ }
5525
5554
  if (!(error instanceof routingControllers.BadRequestError)) return [3 /*break*/, 6];
5526
5555
  res.status(400);
5527
5556
  if (!(error.constructor.name === "ParamRequiredError")) return [3 /*break*/, 2];
5528
- _a = result;
5557
+ _b = result;
5529
5558
  return [4 /*yield*/, this.translator.getTranslation(req.language, "message.parameter-required.error")];
5530
5559
  case 1:
5531
- _a.message = _d.sent();
5560
+ _b.message = _e.sent();
5532
5561
  result.param = error.message;
5533
5562
  return [3 /*break*/, 5];
5534
5563
  case 2:
5535
- if (error instanceof axios.AxiosError) {
5536
- console.log(error.response);
5537
- }
5538
- _b = result;
5539
- _c = error.message;
5540
- if (_c) return [3 /*break*/, 4];
5564
+ _c = result;
5565
+ _d = error.message;
5566
+ if (_d) return [3 /*break*/, 4];
5541
5567
  return [4 /*yield*/, this.translator.getTranslation(req.language, "message.form-validation.error")];
5542
5568
  case 3:
5543
- _c = (_d.sent());
5544
- _d.label = 4;
5569
+ _d = (_e.sent());
5570
+ _e.label = 4;
5545
5571
  case 4:
5546
- _b.message = _c;
5572
+ _c.message = _d;
5547
5573
  result.errors = error["errors"];
5548
- if (this.isDev) {
5574
+ if (error.stack && this.isDev) {
5549
5575
  result.stack = error.stack;
5550
5576
  }
5551
- _d.label = 5;
5577
+ _e.label = 5;
5552
5578
  case 5: return [2 /*return*/, result];
5553
5579
  case 6:
5554
5580
  res.status(error.httpCode || 500);
@@ -7011,6 +7037,7 @@
7011
7037
  exports.padRight = padRight;
7012
7038
  exports.paginate = paginate;
7013
7039
  exports.paginateAggregations = paginateAggregations;
7040
+ exports.prepareUrl = prepareUrl;
7014
7041
  exports.projectStage = projectStage;
7015
7042
  exports.promiseTimeout = promiseTimeout;
7016
7043
  exports.rand = rand;
@@ -7029,6 +7056,7 @@
7029
7056
  exports.uniqueItems = uniqueItems;
7030
7057
  exports.unwindStage = unwindStage;
7031
7058
  exports.valueToPromise = valueToPromise;
7059
+ exports.wrapError = wrapError;
7032
7060
  exports.writeFile = writeFile;
7033
7061
 
7034
7062
  Object.defineProperty(exports, '__esModule', { value: true });