By default, HttpClient does not throw an error for non-2xx status codes. A 404 or 500 response is still a successful HTTP exchange. The server received your request and sent back a response.
import { FetchHttpClient, HttpClient, HttpClientRequest,} from "effect/unstable/http";import { Effect } from "effect";
function fetchNonExistentUser() { return Effect.gen(function* () { const client = yield* HttpClient.HttpClient;
// User 9999 doesn't exist. The API returns 404. const request = HttpClientRequest.get("https://dummyjson.com/users/9999");
const response = yield* client.execute(request);
// This succeeds! The response object is available. console.log("Status:", response.status);
const body = yield* response.json; console.log("Body:", body);
return body; }).pipe(Effect.provide(FetchHttpClient.layer));}
// Test itEffect.runPromise(fetchNonExistentUser());Output:
Status: 404Body: { message: "User with id '9999' not found" }No error is thrown. The 404 response flows through like any other response. This gives you full control. You can inspect the status code and body, and decide how to handle it yourself.
This is different from libraries like Axios, which throw by default on non-2xx responses. Effect’s approach is more explicit: a response is always a response, and you opt in to treating certain status codes as errors.