@jpbs/common 1.1.7 → 1.1.8

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.
@@ -5,14 +5,18 @@ const axios_1 = require("axios");
5
5
  const custom_error_1 = require("../errors/custom-error");
6
6
  const http_status_codes_1 = require("http-status-codes");
7
7
  const errorHandler = (err, _req, res, _next) => {
8
- var _a, _b;
8
+ var _a;
9
9
  if (err instanceof custom_error_1.CustomError) {
10
10
  res.status(err.statusCode).send({ errors: err.serializeErrors() });
11
11
  return;
12
12
  }
13
13
  if (err instanceof axios_1.AxiosError) {
14
- const message = ((_b = (_a = err.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) || 'An error occurred with the external service';
15
- res.status(http_status_codes_1.StatusCodes.BAD_GATEWAY).send({ errors: [{ message }] });
14
+ if (err.response && err.response.data && err.response.data.errors) {
15
+ const message = ((_a = err.response.data.errors[0]) === null || _a === void 0 ? void 0 : _a.message) || 'An error';
16
+ res.status(http_status_codes_1.StatusCodes.BAD_GATEWAY).send({ errors: [{ message }] });
17
+ return;
18
+ }
19
+ res.status(http_status_codes_1.StatusCodes.BAD_GATEWAY).send({ errors: [{ message: 'An error occurred with the external service' }] });
16
20
  return;
17
21
  }
18
22
  res.status(http_status_codes_1.StatusCodes.BAD_REQUEST).send({ errors: [{ message: 'Something went wrong' }] });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jpbs/common",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
4
4
  "main": "./build/index.js",
5
5
  "types": "./build/index.d.ts",
6
6
  "files": [