Skip to content

Commit 86faa42

Browse files
authored
feat(api): add retries on errors (#934)
1 parent 2cb27c5 commit 86faa42

File tree

8 files changed

+49
-91
lines changed

8 files changed

+49
-91
lines changed

package-lock.json

Lines changed: 23 additions & 0 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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"@gravity-ui/websql-autocomplete": "^9.1.0",
2525
"@reduxjs/toolkit": "^2.2.3",
2626
"axios": "^1.6.8",
27+
"axios-retry": "^4.4.0",
2728
"colord": "^2.9.3",
2829
"copy-to-clipboard": "^3.3.3",
2930
"crc-32": "^1.2.2",

src/services/api.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import AxiosWrapper from '@gravity-ui/axios-wrapper';
2+
import type {AxiosWrapperOptions} from '@gravity-ui/axios-wrapper';
23
import type {AxiosRequestConfig} from 'axios';
4+
import axiosRetry from 'axios-retry';
35

46
import {backend as BACKEND, metaBackend as META_BACKEND} from '../store';
57
import type {ComputeApiRequestParams, NodesApiRequestParams} from '../store/reducers/nodes/types';
@@ -54,6 +56,29 @@ type AxiosOptions = {
5456
};
5557

5658
export class YdbEmbeddedAPI extends AxiosWrapper {
59+
constructor(options?: AxiosWrapperOptions) {
60+
super(options);
61+
62+
axiosRetry(this._axios, {
63+
retries: 3,
64+
retryDelay: axiosRetry.exponentialDelay,
65+
});
66+
67+
// Interceptor to process OIDC auth
68+
this._axios.interceptors.response.use(null, function (error) {
69+
const response = error.response;
70+
71+
// OIDC proxy returns 401 response with authUrl in it
72+
// authUrl - external auth service link, after successful auth additional cookies will be appended
73+
// that will allow access to clusters where OIDC proxy is a balancer
74+
if (response && response.status === 401 && response.data?.authUrl) {
75+
return window.location.assign(response.data.authUrl);
76+
}
77+
78+
return Promise.reject(error);
79+
});
80+
}
81+
5782
getPath(path: string) {
5883
return `${BACKEND ?? ''}${path}`;
5984
}

src/store/configureStore.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,6 @@ export function configureStore({
6363
]);
6464
listenForHistoryChange(store, history);
6565

66-
// Interceptor to process OIDC auth
67-
// @ts-expect-error
68-
api._axios.interceptors.response.use(
69-
function (response) {
70-
return Promise.resolve(response);
71-
},
72-
function (error) {
73-
const response = error.response;
74-
75-
// OIDC proxy returns 401 response with authUrl in it
76-
// authUrl - external auth service link, after successful auth additional cookies will be appended
77-
// that will allow access to clusters where OIDC proxy is a balancer
78-
if (response && response.status === 401 && response.data?.authUrl) {
79-
return window.location.assign(response.data.authUrl);
80-
}
81-
82-
return Promise.reject(error);
83-
},
84-
);
85-
8666
window.api = api;
8767

8868
return {history, store};

src/store/reducers/api.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export const api = createApi({
88
* which is why no endpoints are shown below.
99
*/
1010
endpoints: () => ({}),
11-
refetchOnMountOrArgChange: true,
1211
invalidationBehavior: 'immediately',
1312
tagTypes: ['All'],
1413
});

src/store/reducers/host.ts

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/store/reducers/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import executeTopQueries from './executeTopQueries/executeTopQueries';
99
import fullscreen from './fullscreen';
1010
import header from './header/header';
1111
import heatmap from './heatmap';
12-
import host from './host';
1312
import hotKeys from './hotKeys/hotKeys';
1413
import partitions from './partitions/partitions';
1514
import saveQuery from './saveQuery';
@@ -32,7 +31,6 @@ export const rootReducer = {
3231
tooltip,
3332
tablets,
3433
schema,
35-
host,
3634
tenants,
3735
partitions,
3836
executeQuery,

src/types/store/host.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)