Accessing Non-200 HTTP Response Messages in Effect Typescript

is there any way to get access to the messages sent from non 200 messages? i actually need to propagate those to the client and it seems the inner workings of this httpClient api swallow them completely....

//  401 response for the wrong credentials. i need access to this
{ "message": "invalid credentials" }


export const makeLiveAuthService = Effect.gen(function* () {
  const baseURL = yield* Config.nonEmptyString("BASE_URL");
  const defaultClient = yield* HttpClient.HttpClient;

  const client = pipe(defaultClient, HttpClient.mapRequest(HttpClientRequest.prependUrl(baseURL)));

  function login(args: LoginRequest) {
    return pipe(
      HttpClientRequest.post("/authenticate"),
      HttpClientRequest.setHeaders({ "Content-Type": "application/json; charset=UTF-8" }),
      HttpClientRequest.schemaBodyJson(LoginRequest)(args),
      Effect.flatMap(client.execute),
      Effect.flatMap(
        HttpClientResponse.matchStatus({
          "2xx": HttpClientResponse.schemaBodyJson(LoginResponse),
          orElse: (res) => {
            // how do i extract the body of the non 200 response?
            return Effect.fail(res);
          },
        }),
      ),
      Effect.scoped,
    );
  }

  return { login };
});
Was this page helpful?