@konversi/konversi-client 1.5.12 → 1.5.13
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/index.js +20 -7
- package/dist/index.mjs +20 -7
- package/package.json +27 -28
package/dist/index.js
CHANGED
|
@@ -85,16 +85,29 @@ var instance = import_axios.default.create({
|
|
|
85
85
|
baseURL,
|
|
86
86
|
timeout
|
|
87
87
|
});
|
|
88
|
+
var MAX_RETRIES = 36;
|
|
89
|
+
var RETRY_DELAY_MS = 5e3;
|
|
88
90
|
instance.interceptors.response.use(
|
|
89
91
|
(response) => response,
|
|
90
|
-
(error) => {
|
|
91
|
-
var _a, _b, _c, _d, _e;
|
|
92
|
+
(error) => __async(null, null, function* () {
|
|
93
|
+
var _a, _b, _c, _d, _e, _f;
|
|
94
|
+
const config = error.config;
|
|
95
|
+
if (config) {
|
|
96
|
+
config.retryCount = (_a = config.retryCount) != null ? _a : 0;
|
|
97
|
+
const isNetworkError = !error.response && (error.code === "ECONNREFUSED" || error.code === "ENOTFOUND" || error.code === "ECONNRESET" || error.code === "ETIMEDOUT");
|
|
98
|
+
if (isNetworkError && config.retryCount < MAX_RETRIES) {
|
|
99
|
+
config.retryCount++;
|
|
100
|
+
console.log(`API unreachable (${error.code}). Retrying...`);
|
|
101
|
+
yield new Promise((resolve) => setTimeout(resolve, RETRY_DELAY_MS));
|
|
102
|
+
return instance(config);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
92
105
|
if (error.isAxiosError) {
|
|
93
|
-
const method = (
|
|
94
|
-
const url = (
|
|
95
|
-
const status = (
|
|
106
|
+
const method = (_c = (_b = error.config) == null ? void 0 : _b.method) == null ? void 0 : _c.toUpperCase();
|
|
107
|
+
const url = (_d = error.config) == null ? void 0 : _d.url;
|
|
108
|
+
const status = (_e = error.response) == null ? void 0 : _e.status;
|
|
96
109
|
const message = error.message;
|
|
97
|
-
const responseBody = (
|
|
110
|
+
const responseBody = (_f = error.response) == null ? void 0 : _f.data;
|
|
98
111
|
const cleanError = new Error(
|
|
99
112
|
[
|
|
100
113
|
`Konversi call failed`,
|
|
@@ -109,7 +122,7 @@ instance.interceptors.response.use(
|
|
|
109
122
|
return Promise.reject(cleanError);
|
|
110
123
|
}
|
|
111
124
|
return Promise.reject(error);
|
|
112
|
-
}
|
|
125
|
+
})
|
|
113
126
|
);
|
|
114
127
|
var setBaseUrl = (baseUrl) => {
|
|
115
128
|
instance.defaults.baseURL = baseUrl;
|
package/dist/index.mjs
CHANGED
|
@@ -47,16 +47,29 @@ var instance = axios.create({
|
|
|
47
47
|
baseURL,
|
|
48
48
|
timeout
|
|
49
49
|
});
|
|
50
|
+
var MAX_RETRIES = 36;
|
|
51
|
+
var RETRY_DELAY_MS = 5e3;
|
|
50
52
|
instance.interceptors.response.use(
|
|
51
53
|
(response) => response,
|
|
52
|
-
(error) => {
|
|
53
|
-
var _a, _b, _c, _d, _e;
|
|
54
|
+
(error) => __async(null, null, function* () {
|
|
55
|
+
var _a, _b, _c, _d, _e, _f;
|
|
56
|
+
const config = error.config;
|
|
57
|
+
if (config) {
|
|
58
|
+
config.retryCount = (_a = config.retryCount) != null ? _a : 0;
|
|
59
|
+
const isNetworkError = !error.response && (error.code === "ECONNREFUSED" || error.code === "ENOTFOUND" || error.code === "ECONNRESET" || error.code === "ETIMEDOUT");
|
|
60
|
+
if (isNetworkError && config.retryCount < MAX_RETRIES) {
|
|
61
|
+
config.retryCount++;
|
|
62
|
+
console.log(`API unreachable (${error.code}). Retrying...`);
|
|
63
|
+
yield new Promise((resolve) => setTimeout(resolve, RETRY_DELAY_MS));
|
|
64
|
+
return instance(config);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
54
67
|
if (error.isAxiosError) {
|
|
55
|
-
const method = (
|
|
56
|
-
const url = (
|
|
57
|
-
const status = (
|
|
68
|
+
const method = (_c = (_b = error.config) == null ? void 0 : _b.method) == null ? void 0 : _c.toUpperCase();
|
|
69
|
+
const url = (_d = error.config) == null ? void 0 : _d.url;
|
|
70
|
+
const status = (_e = error.response) == null ? void 0 : _e.status;
|
|
58
71
|
const message = error.message;
|
|
59
|
-
const responseBody = (
|
|
72
|
+
const responseBody = (_f = error.response) == null ? void 0 : _f.data;
|
|
60
73
|
const cleanError = new Error(
|
|
61
74
|
[
|
|
62
75
|
`Konversi call failed`,
|
|
@@ -71,7 +84,7 @@ instance.interceptors.response.use(
|
|
|
71
84
|
return Promise.reject(cleanError);
|
|
72
85
|
}
|
|
73
86
|
return Promise.reject(error);
|
|
74
|
-
}
|
|
87
|
+
})
|
|
75
88
|
);
|
|
76
89
|
var setBaseUrl = (baseUrl) => {
|
|
77
90
|
instance.defaults.baseURL = baseUrl;
|
package/package.json
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@konversi/konversi-client",
|
|
3
|
-
"version": "1.5.
|
|
4
|
-
"main": "dist/index.js",
|
|
5
|
-
"module": "dist/index.mjs",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
},
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@konversi/konversi-client",
|
|
3
|
+
"version": "1.5.13",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"module": "dist/index.mjs",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"keywords": [],
|
|
8
|
+
"author": "",
|
|
9
|
+
"license": "ISC",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"axios": "^1.6.8",
|
|
12
|
+
"ts-node": "^10.9.2"
|
|
13
|
+
},
|
|
14
|
+
"description": "",
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"tsup": "^8.2.4",
|
|
17
|
+
"typescript": "^5.4.5"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
24
|
+
"build": "tsup index.ts --format cjs,esm --dts",
|
|
25
|
+
"lint": "tsc"
|
|
26
|
+
}
|
|
27
|
+
}
|