8000 Merge pull request #86 from apisearch-io/feature/deleted-axios-retry-… · apisearch-io/javascript-client@c59f066 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jun 25, 2025. It is now read-only.

Commit c59f066

Browse files
authored
Merge pull request #86 from apisearch-io/feature/deleted-axios-retry-dependency
Deleted Axios Retry dependency + 0.3.7
2 parents d48caac + 583167d commit c59f066

File tree

11 files changed

+140
-1437
lines changed

11 files changed

+140
-1437
lines changed

dist/apisearch.js

Lines changed: 43 additions & 1330 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/apisearch.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/apisearch.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/apisearch.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Apisearch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var Apisearch = /** @class */ (function () {
2626
*/
2727
Apisearch.createRepository = function (config) {
2828
Apisearch.ensureRepositoryConfigIsValid(config);
29-
config.options = tslib_1.__assign({ api_version: "v1", override_queries: true, timeout: 5000 }, config.options);
29+
config.options = tslib_1.__assign({ api_version: "v1", override_queries: true, timeout: 3000 }, config.options);
3030
/**
3131
* Client
3232
*/

lib/Http/AxiosClient.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,10 @@ export declare class AxiosClient extends Client implements HttpClient {
4343
* @param url
4444
*/
4545
generateCancelToken(url: string): void;
46+
/**
47+
* @param url
48+
* @param options
49+
* @param retries
50+
*/
51+
fetch(url: string, options: {}, retries: number): any;
4652
}

lib/Http/AxiosClient.js

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ exports.__esModule = true;
33
exports.AxiosClient = void 0;
44
var tslib_1 = require("tslib");
55
var axios_1 = require("axios");
6-
var axios_retry_1 = require("axios-retry");
76
var __1 = require("..");
87
var Client_1 = require("./Client");
98
var Response_1 = require("./Response");
@@ -43,8 +42,7 @@ var AxiosClient = /** @class */ (function (_super) {
4342
if (parameters === void 0) { parameters = {}; }
4443
if (data === void 0) { data = {}; }
4544
return tslib_1.__awaiter(this, void 0, void 0, function () {
46-
var headers, axiosRequestConfig,< 9E81 /span> sendRequest, axiosResponse, error_1, response;
47-
var _this = this;
45+
var headers, axiosRequestConfig, axiosResponse, error_1, response;
4846
return tslib_1.__generator(this, function (_a) {
4947
switch (_a.label) {
5048
case 0:
@@ -70,30 +68,15 @@ var AxiosClient = /** @class */ (function (_super) {
7068
transformRequest: [function (rawData) { return JSON.stringify(rawData); }],
7169
url: url + "?" + Client_1.Client.objectToUrlParameters(tslib_1.__assign(tslib_1.__assign({}, parameters), {
7270
token: credentials.token
73-
})).replace(/#/g, '%23')
71+
})).replace(/#/g, "%23")
7472
};
7573
if (typeof this.cancelToken[url] !== "undefined") {
7674
axiosRequestConfig.cancelToken = this.cancelToken[url].token;
7775
}
7876
_a.label = 1;
7977
case 1:
8078
_a.trys.push([1, 3, , 4]);
81-
axios_retry_1["default"](axios_1["default"], {
82-
retries: 3,
83-
shouldResetTimeout: true,
84-
retryCondition: function (error) {
85-
return axios_retry_1["default"].isNetworkOrIdempotentRequestError(error)
86-
|| error.code === "ECONNABORTED"
87-
|| error.message === "Network Error";
88-
}
89-
});
90-
sendRequest = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
91-
switch (_a.label) {
92-
case 0: return [4 /*yield*/, axios_1["default"].request(axiosRequestConfig)];
93-
case 1: return [2 /*return*/, _a.sent()];
94-
}
95-
}); }); };
96-
return [4 /*yield*/, sendRequest()];
79+
return [4 /*yield*/, this.fetch(url, axiosRequestConfig, 3)];
9780
case 2:
9881
axiosResponse = _a.sent();
9982
return [2 /*return*/, new Response_1.Response(axiosResponse.status, axiosResponse.data)];
@@ -134,6 +117,45 @@ var AxiosClient = /** @class */ (function (_super) {
134117
AxiosClient.prototype.generateCancelToken = function (url) {
135118
this.cancelToken[url] = axios_1["default"].CancelToken.source();
136119
};
120+
/**
121+
* @param url
122+
* @param options
123+
* @param retries
124+
*/
125+
AxiosClient.prototype.fetch = function (url, options, retries) {
126+
return tslib_1.__awaiter(this, void 0, void 0, function () {
127+
var _this = this;
128+
return tslib_1.__generator(this, function (_a) {
129+
switch (_a.label) {
130+
case 0: return [4 /*yield*/, axios_1["default"]
131+
.request(options)
132+
.then(function (response) {
133+
return {
134+
data: response.data,
135+
status: response.status
136+
};
137+
})["catch"](function (error) {
138+
var response = error.response;
139+
if (error.code !== undefined &&
140+
error.code !== "ECONNREFUSED" 10000 &&
141+
error.code !== "ECONNABORTED" &&
142+
error.message !== "Network Error") {
143+
return {
144+
data: response.data,
145+
status: response.status
146+
};
147+
}
148+
if (retries <= 0) {
149+
throw error;
150+
}
151+
retries = retries - 1;
152+
return _this.fetch(url, options, retries);
153+
})];
154+
case 1: return [2 /*return*/, _a.sent()];
155+
}
156+
});
157+
});
158+
};
137159
return AxiosClient;
138160
}(Client_1.Client));
139161
exports.AxiosClient = AxiosClient;

package-lock.json

Lines changed: 2 additions & 66 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "apisearch",
3-
"version": "0.3.6",
3+
"version": "0.3.7",
44
"description": "Javascript client for Apisearch.",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",
@@ -51,7 +51,6 @@
5151
},
5252
"dependencies": {
5353
"axios": ">=0.21.1",
54-
"axios-retry": "^3.2.4",
5554
"ts-md5": "^1.2.4"
5655
}
5756
}

src/Apisearch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default class Apisearch {
4343
config.options = {
4444
api_version: "v1",
4545
override_queries: true,
46-
timeout: 5000,
46+
timeout: 3000,
4747
...config.options,
4848
};
4949

0 commit comments

Comments
 (0)
0