diff --git a/.changeset/popular-squids-love.md b/.changeset/popular-squids-love.md new file mode 100644 index 00000000000..b38d6b87b18 --- /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 7b6f68b0eda..2cdde71362f 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: NoInfer) => Effect.Effect<_, E2, R2> + ): (self: HttpClient.With) => HttpClient.With + ( + self: HttpClient.With, + f: (e: NoInfer) => 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 0a62df595bb..f6c0f9b2342 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: NoInfer) => Effect.Effect<_, E2, R2> + ) => (self: Client.HttpClient.With) => Client.HttpClient.With, + ( + self: Client.HttpClient.With, + f: (e: NoInfer) => Effect.Effect<_, E2, R2> + ) => Client.HttpClient.With +>(2, (self, f) => transformResponse(self, Effect.tapError(f))) + /** @internal */ export const tapRequest = dual< <_, E2, R2>(