Effect CommunityEC
Effect Community14mo ago
9 replies
Florian

HttpApiClient: Handling untagged errors originating from third parties

Hi, when using an HttpApiClient: How can I handle / transform an error that is not a tagged error originating from effect? Use case: We have an AWS API where authentication is handle by AWS and unauthenticated request never reach our effect codebase. When using HttpApiClient.make(api) we get an error:

ParseError: (Unauthorized (Encoded side) <-> Unauthorized)
─ Encoded side transformation failure
─ Unauthorized (Encoded side)
["_tag"]
─ is missing

What I would like to achieve is to transform this error to a tagged error on the client side (since I have no control over the Unauthenticated error from AWS).

I tried the following but to no avail:

HttpApiClient.make(api, {
    baseUrl,
    transformClient: (client) =>
      client.pipe(
        // HttpClient.tapRequest(Console.log),
        HttpClient.catchAll((e) => {
          return Effect.succeed(
            HttpClientResponse.fromWeb(e.request, new Response("", { status: 401 })),
          );
        }),
      ),
  })
Was this page helpful?