Skip to content

Commit

Permalink
Add HttpClient.tapError (#4225)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim <[email protected]>
  • Loading branch information
thewilkybarkid and tim-smart authored Jan 14, 2025
1 parent ff7c07d commit 7b3d58d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/popular-squids-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/platform": patch
---

Add HttpClient.tapError
16 changes: 16 additions & 0 deletions packages/platform/src/HttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,22 @@ export const tap: {
): HttpClient.With<E | E2, R | R2>
} = 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<E>) => Effect.Effect<_, E2, R2>
): <R>(self: HttpClient.With<E, R>) => HttpClient.With<E | E2, R | R2>
<E, R, _, E2, R2>(
self: HttpClient.With<E, R>,
f: (e: NoInfer<E>) => Effect.Effect<_, E2, R2>
): HttpClient.With<E | E2, R | R2>
} = internal.tapError

/**
* Performs an additional effect on the request before sending it.
*
Expand Down
11 changes: 11 additions & 0 deletions packages/platform/src/internal/httpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,17 @@ export const tap = dual<
) => Client.HttpClient.With<E | E2, R | R2>
>(2, (self, f) => transformResponse(self, Effect.tap(f)))

/** @internal */
export const tapError = dual<
<_, E, E2, R2>(
f: (e: NoInfer<E>) => Effect.Effect<_, E2, R2>
) => <R>(self: Client.HttpClient.With<E, R>) => Client.HttpClient.With<E | E2, R | R2>,
<E, R, _, E2, R2>(
self: Client.HttpClient.With<E, R>,
f: (e: NoInfer<E>) => Effect.Effect<_, E2, R2>
) => Client.HttpClient.With<E | E2, R | R2>
>(2, (self, f) => transformResponse(self, Effect.tapError(f)))

/** @internal */
export const tapRequest = dual<
<_, E2, R2>(
Expand Down

0 comments on commit 7b3d58d

Please sign in to comment.