Skip to content

Commit c9cfcfd

Browse files
committed
feat: retry retry-able errors
1 parent 38ef992 commit c9cfcfd

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/client.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ import { Credentials, fromStaticCredentials } from "./credentials.ts";
66
import type { AwsErrorMeta } from "./error.ts";
77
import { DefaultFetch, Fetch } from "./fetch.service.ts";
88
import type { ProtocolHandler } from "./protocols/interface.ts";
9+
import * as Schedule from "effect/Schedule";
10+
11+
export const retryableErrorTags = [
12+
"InternalFailure",
13+
"RequestExpired",
14+
"ServiceException",
15+
"ServiceUnavailable",
16+
"ThrottlingException",
17+
"TooManyRequestsException",
18+
];
919

1020
const errorTags: {
1121
[serviceName: string]: {
@@ -247,7 +257,21 @@ export function createServiceProxy<T>(
247257
);
248258
}
249259
});
250-
return program;
260+
261+
return program.pipe(
262+
Effect.tapError((e) =>
263+
Effect.logDebug("AWS Request Failed, Retrying...", {
264+
error: e,
265+
}),
266+
),
267+
Effect.retry({
268+
schedule: Schedule.intersect(
269+
Schedule.exponential("100 millis"),
270+
Schedule.recurs(5),
271+
),
272+
while: (e) => retryableErrorTags.includes(e._tag),
273+
}),
274+
);
251275
};
252276
},
253277
},

0 commit comments

Comments
 (0)