From c9cfcfdcdaece1070fca1b7fe6ce8edc768a8551 Mon Sep 17 00:00:00 2001 From: Michael K <35264484+Mkassabov@users.noreply.github.com> Date: Wed, 12 Nov 2025 11:13:27 -0500 Subject: [PATCH] feat: retry retry-able errors --- src/client.ts | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/client.ts b/src/client.ts index 87c6fe58..6f6533ea 100644 --- a/src/client.ts +++ b/src/client.ts @@ -6,6 +6,16 @@ import { Credentials, fromStaticCredentials } from "./credentials.ts"; import type { AwsErrorMeta } from "./error.ts"; import { DefaultFetch, Fetch } from "./fetch.service.ts"; import type { ProtocolHandler } from "./protocols/interface.ts"; +import * as Schedule from "effect/Schedule"; + +export const retryableErrorTags = [ + "InternalFailure", + "RequestExpired", + "ServiceException", + "ServiceUnavailable", + "ThrottlingException", + "TooManyRequestsException", +]; const errorTags: { [serviceName: string]: { @@ -247,7 +257,21 @@ export function createServiceProxy( ); } }); - return program; + + return program.pipe( + Effect.tapError((e) => + Effect.logDebug("AWS Request Failed, Retrying...", { + error: e, + }), + ), + Effect.retry({ + schedule: Schedule.intersect( + Schedule.exponential("100 millis"), + Schedule.recurs(5), + ), + while: (e) => retryableErrorTags.includes(e._tag), + }), + ); }; }, },