exnet-routing 1.2.36 → 1.2.38

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.
@@ -6,6 +6,7 @@ export declare const apiFetch: {
6
6
  setHostApi: (h: string) => void;
7
7
  setBaseUrl: (b: string) => void;
8
8
  setHeaders: (h: AxiosHeaders | undefined) => void;
9
+ setOnError: (cb: ((error: any) => void) | undefined) => void;
9
10
  fetch: (urlInput: string, method?: RequestInit["method"] | undefined, body?: any, searchParams?: any, queryParams?: {
10
11
  [key: string]: string;
11
12
  }) => Promise<any>;
@@ -9,6 +9,7 @@ const axios_1 = __importDefault(require("axios"));
9
9
  let host;
10
10
  let baseUrl;
11
11
  let headers;
12
+ let onErrorCallback;
12
13
  const apiUrlBuilder = (segment = "", baseUrl = "", host = "") => {
13
14
  const path = (0, path_1.join)(baseUrl, segment);
14
15
  return host + path;
@@ -24,7 +25,11 @@ exports.apiFetch = {
24
25
  setHeaders: (h) => {
25
26
  headers = h;
26
27
  },
28
+ setOnError: (cb) => {
29
+ onErrorCallback = cb;
30
+ },
27
31
  fetch: async (urlInput, method, body, searchParams, queryParams) => {
32
+ var _a, _b, _c;
28
33
  try {
29
34
  let url = (0, exports.apiUrlBuilder)(urlInput, baseUrl, host);
30
35
  if (queryParams) {
@@ -63,6 +68,13 @@ exports.apiFetch = {
63
68
  return res.data;
64
69
  }
65
70
  catch (error) {
71
+ if (axios_1.default.isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data)) {
72
+ onErrorCallback === null || onErrorCallback === void 0 ? void 0 : onErrorCallback(error.response.data);
73
+ const apiError = new Error(((_c = (_b = error.response.data) === null || _b === void 0 ? void 0 : _b.error) === null || _c === void 0 ? void 0 : _c.message) || error.message);
74
+ apiError.response = error.response.data;
75
+ apiError.status = error.response.status;
76
+ throw apiError;
77
+ }
66
78
  throw new Error(`Request failed: ${error}`);
67
79
  }
68
80
  },
package/dist/index.d.ts CHANGED
@@ -5,6 +5,8 @@ export { EventsRouter, createEventsRouter } from "./routes/events";
5
5
  export { wsEvents, WsEventsType } from "./events";
6
6
  export * from "./core/events/_type";
7
7
  export * from "./models";
8
+ export type { UploadContext, UploadStatus } from "./models/_upload";
9
+ export { UploadContextEnum, UploadStatusEnum } from "./models/_upload";
8
10
  type RecordHeaders = {
9
11
  [x: string]: AxiosHeaderValue | undefined;
10
12
  Accept?: AxiosHeaderValue | undefined;
@@ -26,4 +28,5 @@ export declare class APIRouter {
26
28
  routes(): TransformApi<typeof index>;
27
29
  getHostApi(): string;
28
30
  getBasePath(): string;
31
+ onError(callback: (error: any) => void): APIRouter;
29
32
  }
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.APIRouter = exports.wsEvents = exports.createEventsRouter = exports.EventsRouter = void 0;
17
+ exports.APIRouter = exports.UploadStatusEnum = exports.UploadContextEnum = exports.wsEvents = exports.createEventsRouter = exports.EventsRouter = void 0;
18
18
  const _untils_1 = require("./core/api/_untils");
19
19
  const index_1 = require("./core/index");
20
20
  const axios_1 = require("axios");
@@ -27,6 +27,9 @@ Object.defineProperty(exports, "wsEvents", { enumerable: true, get: function ()
27
27
  __exportStar(require("./core/events/_type"), exports);
28
28
  // Re-export models/types
29
29
  __exportStar(require("./models"), exports);
30
+ var _upload_1 = require("./models/_upload");
31
+ Object.defineProperty(exports, "UploadContextEnum", { enumerable: true, get: function () { return _upload_1.UploadContextEnum; } });
32
+ Object.defineProperty(exports, "UploadStatusEnum", { enumerable: true, get: function () { return _upload_1.UploadStatusEnum; } });
30
33
  class APIRouter {
31
34
  constructor(hostApi, basePath) {
32
35
  this.hostApi = hostApi;
@@ -55,6 +58,10 @@ class APIRouter {
55
58
  getBasePath() {
56
59
  return this.basePath;
57
60
  }
61
+ onError(callback) {
62
+ _untils_1.apiFetch.setOnError(callback);
63
+ return this;
64
+ }
58
65
  }
59
66
  exports.APIRouter = APIRouter;
60
67
  // Demo use
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exnet-routing",
3
- "version": "1.2.36",
3
+ "version": "1.2.38",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [