exnet-routing 1.2.35 → 1.2.37
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/dist/core/api/_untils.d.ts +1 -0
- package/dist/core/api/_untils.js +12 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -0
- package/package.json +1 -1
|
@@ -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>;
|
package/dist/core/api/_untils.js
CHANGED
|
@@ -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
|
@@ -4,6 +4,7 @@ import { AxiosHeaderValue } from "axios";
|
|
|
4
4
|
export { EventsRouter, createEventsRouter } from "./routes/events";
|
|
5
5
|
export { wsEvents, WsEventsType } from "./events";
|
|
6
6
|
export * from "./core/events/_type";
|
|
7
|
+
export * from "./models";
|
|
7
8
|
type RecordHeaders = {
|
|
8
9
|
[x: string]: AxiosHeaderValue | undefined;
|
|
9
10
|
Accept?: AxiosHeaderValue | undefined;
|
|
@@ -25,4 +26,5 @@ export declare class APIRouter {
|
|
|
25
26
|
routes(): TransformApi<typeof index>;
|
|
26
27
|
getHostApi(): string;
|
|
27
28
|
getBasePath(): string;
|
|
29
|
+
onError(callback: (error: any) => void): APIRouter;
|
|
28
30
|
}
|
package/dist/index.js
CHANGED
|
@@ -25,6 +25,8 @@ Object.defineProperty(exports, "createEventsRouter", { enumerable: true, get: fu
|
|
|
25
25
|
var events_2 = require("./events");
|
|
26
26
|
Object.defineProperty(exports, "wsEvents", { enumerable: true, get: function () { return events_2.wsEvents; } });
|
|
27
27
|
__exportStar(require("./core/events/_type"), exports);
|
|
28
|
+
// Re-export models/types
|
|
29
|
+
__exportStar(require("./models"), exports);
|
|
28
30
|
class APIRouter {
|
|
29
31
|
constructor(hostApi, basePath) {
|
|
30
32
|
this.hostApi = hostApi;
|
|
@@ -53,6 +55,10 @@ class APIRouter {
|
|
|
53
55
|
getBasePath() {
|
|
54
56
|
return this.basePath;
|
|
55
57
|
}
|
|
58
|
+
onError(callback) {
|
|
59
|
+
_untils_1.apiFetch.setOnError(callback);
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
56
62
|
}
|
|
57
63
|
exports.APIRouter = APIRouter;
|
|
58
64
|
// Demo use
|