From 767a24469893fb973611c63b09dd19a9e4c1c0f6 Mon Sep 17 00:00:00 2001 From: Chris Wilkinson Date: Wed, 8 Jan 2025 15:30:42 +0000 Subject: [PATCH 1/3] Add HttpClient.tapError --- .changeset/popular-squids-love.md | 5 +++++ packages/platform/src/HttpClient.ts | 16 ++++++++++++++++ packages/platform/src/internal/httpClient.ts | 11 +++++++++++ 3 files changed, 32 insertions(+) create mode 100644 .changeset/popular-squids-love.md diff --git a/.changeset/popular-squids-love.md b/.changeset/popular-squids-love.md new file mode 100644 index 0000000000..b38d6b87b1 --- /dev/null +++ b/.changeset/popular-squids-love.md @@ -0,0 +1,5 @@ +--- +"@effect/platform": patch +--- + +Add HttpClient.tapError diff --git a/packages/platform/src/HttpClient.ts b/packages/platform/src/HttpClient.ts index 7b6f68b0ed..f58d3fca2e 100644 --- a/packages/platform/src/HttpClient.ts +++ b/packages/platform/src/HttpClient.ts @@ -549,6 +549,22 @@ export const tap: { ): HttpClient.With } = internal.tap +/** + * Performs an additional effect after an unsuccessful request. + * + * @since 1.0.0 + * @category mapping & sequencing + */ +export const tapError: { + <_, E, E2, R2>( + f: (e: E) => Effect.Effect<_, E2, R2> + ): (self: HttpClient.With) => HttpClient.With + ( + self: HttpClient.With, + f: (e: E) => Effect.Effect<_, E2, R2> + ): HttpClient.With +} = internal.tapError + /** * Performs an additional effect on the request before sending it. * diff --git a/packages/platform/src/internal/httpClient.ts b/packages/platform/src/internal/httpClient.ts index 0a62df595b..dc367205dd 100644 --- a/packages/platform/src/internal/httpClient.ts +++ b/packages/platform/src/internal/httpClient.ts @@ -621,6 +621,17 @@ export const tap = dual< ) => Client.HttpClient.With >(2, (self, f) => transformResponse(self, Effect.tap(f))) +/** @internal */ +export const tapError = dual< + <_, E, E2, R2>( + f: (e: E) => Effect.Effect<_, E2, R2> + ) => (self: Client.HttpClient.With) => Client.HttpClient.With, + ( + self: Client.HttpClient.With, + f: (e: E) => Effect.Effect<_, E2, R2> + ) => Client.HttpClient.With +>(2, (self, f) => transformResponse(self, Effect.tapError(f))) + /** @internal */ export const tapRequest = dual< <_, E2, R2>( From 09354af8888e3616ea1f16b817b5a4cb8765a6e0 Mon Sep 17 00:00:00 2001 From: Chris Wilkinson Date: Tue, 14 Jan 2025 11:02:18 +0000 Subject: [PATCH 2/3] Update packages/platform/src/HttpClient.ts Co-authored-by: Tim --- packages/platform/src/HttpClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/platform/src/HttpClient.ts b/packages/platform/src/HttpClient.ts index f58d3fca2e..ffdd4173bb 100644 --- a/packages/platform/src/HttpClient.ts +++ b/packages/platform/src/HttpClient.ts @@ -557,7 +557,7 @@ export const tap: { */ export const tapError: { <_, E, E2, R2>( - f: (e: E) => Effect.Effect<_, E2, R2> + f: (e: NoInfer) => Effect.Effect<_, E2, R2> ): (self: HttpClient.With) => HttpClient.With ( self: HttpClient.With, From 16c25764a66b664df6122bb2b660d6a6f25b100d Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 15 Jan 2025 10:38:40 +1300 Subject: [PATCH 3/3] wip --- packages/platform/src/HttpClient.ts | 4 ++-- packages/platform/src/internal/httpClient.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/platform/src/HttpClient.ts b/packages/platform/src/HttpClient.ts index ffdd4173bb..2cdde71362 100644 --- a/packages/platform/src/HttpClient.ts +++ b/packages/platform/src/HttpClient.ts @@ -558,10 +558,10 @@ export const tap: { export const tapError: { <_, E, E2, R2>( f: (e: NoInfer) => Effect.Effect<_, E2, R2> - ): (self: HttpClient.With) => HttpClient.With + ): (self: HttpClient.With) => HttpClient.With ( self: HttpClient.With, - f: (e: E) => Effect.Effect<_, E2, R2> + f: (e: NoInfer) => Effect.Effect<_, E2, R2> ): HttpClient.With } = internal.tapError diff --git a/packages/platform/src/internal/httpClient.ts b/packages/platform/src/internal/httpClient.ts index dc367205dd..f6c0f9b234 100644 --- a/packages/platform/src/internal/httpClient.ts +++ b/packages/platform/src/internal/httpClient.ts @@ -624,11 +624,11 @@ export const tap = dual< /** @internal */ export const tapError = dual< <_, E, E2, R2>( - f: (e: E) => Effect.Effect<_, E2, R2> + f: (e: NoInfer) => Effect.Effect<_, E2, R2> ) => (self: Client.HttpClient.With) => Client.HttpClient.With, ( self: Client.HttpClient.With, - f: (e: E) => Effect.Effect<_, E2, R2> + f: (e: NoInfer) => Effect.Effect<_, E2, R2> ) => Client.HttpClient.With >(2, (self, f) => transformResponse(self, Effect.tapError(f)))