Skip to content

Commit 6f373b1

Browse files
Use backoff in retry
1 parent db3708e commit 6f373b1

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/services/ldapClient.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,17 @@ export async function SearchAllAsync(groupName: string): SearchAllResponse {
143143
// TODO: do not directly use axios.create from within a function like this
144144
// it will cause a new client to be made per request.
145145
const httpClient = axios.create();
146-
axiosRetry(httpClient, { retries: 5 });
146+
axiosRetry(httpClient, {
147+
retries: 5,
148+
retryDelay: (retryCount) => {
149+
Log(`Retry attempt: ${retryCount}`);
150+
return retryCount * 2000;
151+
},
152+
retryCondition: (error:any) => {
153+
// if retry condition is not specified, by default idempotent requests are retried
154+
return error.response.status < 200 || error.response.status > 299 ;
155+
}
156+
});
147157

148158
async function ForwardSearch(groupName: string) : SearchAllResponse {
149159
Log(`Forwarding request to '${process.env.SOURCE_PROXY}'`);
@@ -154,7 +164,10 @@ async function ForwardSearch(groupName: string) : SearchAllResponse {
154164
try{
155165
const result = await httpClient.get(requestUrl);
156166
Log(`Results for ${groupName}: ${result}`);
157-
return result.data as SearchAllResponse;
167+
return {
168+
Succeeded: true,
169+
...result.data
170+
}
158171
}
159172
catch(e) {
160173
Log(`Error when retrieving results for ${groupName}: ${e}`);

0 commit comments

Comments
 (0)