Skip to content

Commit 53853b7

Browse files
Merge pull request #209 from blockful/feat/interceptors
add: interceptors on the axios mock
2 parents efed148 + 672656c commit 53853b7

3 files changed

Lines changed: 52 additions & 2 deletions

File tree

apps/integrated-tests/src/mocks/http-client-mock.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ export class HttpClientMockSetup {
1919
delete: createMockFunction(),
2020
defaults: {
2121
baseURL: 'http://mocked-endpoint.com/graphql'
22+
},
23+
interceptors: {
24+
request: { use: () => 0, eject: () => {} },
25+
response: { use: () => 0, eject: () => {} }
2226
}
2327
} as any;
2428
}

packages/anticapture-client/dist/anticapture-client.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type VotesOnchain = NonNullable<ListVotesOnchainsQuery['votesOnchains']['items']
88
type ProposalNonVoter = z.infer<typeof SafeProposalNonVotersResponseSchema>['proposalNonVoters']['items'][0];
99
export declare class AnticaptureClient {
1010
private readonly httpClient;
11-
constructor(httpClient: AxiosInstance);
11+
constructor(httpClient: AxiosInstance, maxRetries?: number, timeout?: number);
1212
/**
1313
* Recursively normalizes Ethereum addresses in an object/array structure
1414
* @param obj - Any value to process

packages/anticapture-client/dist/anticapture-client.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,59 @@
11
"use strict";
2+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3+
if (k2 === undefined) k2 = k;
4+
var desc = Object.getOwnPropertyDescriptor(m, k);
5+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6+
desc = { enumerable: true, get: function() { return m[k]; } };
7+
}
8+
Object.defineProperty(o, k2, desc);
9+
}) : (function(o, m, k, k2) {
10+
if (k2 === undefined) k2 = k;
11+
o[k2] = m[k];
12+
}));
13+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14+
Object.defineProperty(o, "default", { enumerable: true, value: v });
15+
}) : function(o, v) {
16+
o["default"] = v;
17+
});
18+
var __importStar = (this && this.__importStar) || (function () {
19+
var ownKeys = function(o) {
20+
ownKeys = Object.getOwnPropertyNames || function (o) {
21+
var ar = [];
22+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23+
return ar;
24+
};
25+
return ownKeys(o);
26+
};
27+
return function (mod) {
28+
if (mod && mod.__esModule) return mod;
29+
var result = {};
30+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31+
__setModuleDefault(result, mod);
32+
return result;
33+
};
34+
})();
235
Object.defineProperty(exports, "__esModule", { value: true });
336
exports.AnticaptureClient = void 0;
37+
const axios_retry_1 = __importStar(require("axios-retry"));
438
const graphql_1 = require("graphql");
539
const viem_1 = require("viem");
640
const graphql_2 = require("./gql/graphql");
741
const schemas_1 = require("./schemas");
842
class AnticaptureClient {
9-
constructor(httpClient) {
43+
constructor(httpClient, maxRetries = 4, timeout = 15000) {
1044
this.httpClient = httpClient;
45+
this.httpClient.defaults.timeout = timeout;
46+
(0, axios_retry_1.default)(this.httpClient, {
47+
retries: maxRetries,
48+
retryDelay: axios_retry_1.exponentialDelay, // 1s, 2s, 4s, 8s
49+
retryCondition: (error) => {
50+
return (0, axios_retry_1.isNetworkOrIdempotentRequestError)(error) ||
51+
(error.response?.status !== undefined && error.response.status >= 500);
52+
},
53+
onRetry: (retryCount, error, requestConfig) => {
54+
console.warn(`[AnticaptureClient] Retry ${retryCount}/${maxRetries} for ${requestConfig.url || 'request'}: ${error.message}`);
55+
},
56+
});
1157
}
1258
/**
1359
* Recursively normalizes Ethereum addresses in an object/array structure

0 commit comments

Comments
 (0)