Handling Error Schemas in HttpClient with Effect Typescript

Is there a way to pass an error schema to the HttpClient, so that, if the response match the schema, then the effect fail ?

I want to avoid my code:

const resp = yield* HttpClientRequest.get(
  "https://www.googleapis.com/calendar/v3/users/me/calendarList",
).pipe(
  HttpClientRequest.bearerToken(accessToken),
  httpClient.execute,
  Effect.andThen(HttpClientResponse.schemaBodyJson(S.Union(GoogleApiError, S.Any))), 
  Effect.scoped,
);

const isError = S.is(GoogleApiError);

if (isError(resp)) {
  return yield* Effect.fail(new GoogleAccessTokenExpired({ expiredAccessToken: accessToken }));
}
Was this page helpful?