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