import { Data, Effect } from "effect";
export class FetchError extends Data.TaggedError('FetchError') {
}
export class NotFoundError extends Data.TaggedError('NotFoundError') {
}
export const httpClient = (input, init) => Effect.gen(function* () {
    const response = yield* Effect.tryPromise({
        try: () => fetch(input, init),
        catch: error => new FetchError({ cause: error }),
    });
    if (response.status === 404) {
        return yield* new NotFoundError({ url: response.url });
    }
    return response;
});
export class ResponseTextError extends Data.TaggedError('ResponseTextError') {
    constructor(error) {
        super(new Error(`Failed to read response text`, { cause: error }));
    }
}
export const responseAsText = (res) => Effect.tryPromise({
    try: () => res.text(),
    catch: error => new ResponseTextError(error),
});
