import { HttpClientError } from "@effect/platform" import { AlertDialog, Button, Flex, Text } from "@radix-ui/themes" import { ErrorHandler } from "@reffuse/extension-query" import { Cause, Chunk, Context, Effect, Match, Option, Stream } from "effect" import { useState } from "react" import { R } from "./reffuse" export class QueryErrorHandler extends ErrorHandler.Tag("QueryErrorHandler")() {} export const QueryErrorHandlerLive = ErrorHandler.layer(QueryErrorHandler) export function VQueryErrorHandler() { const [failure, setFailure] = useState(Option.none> >>()) R.useFork(() => QueryErrorHandler.pipe(Effect.flatMap(handler => Stream.runForEach(handler.errors, v => Effect.sync(() => setFailure(Option.some(v)) )) )), []) return Option.match(failure, { onSome: v => ( Error {Cause.failures(v).pipe( Chunk.head, Option.getOrThrow, Match.value, Match.tag("RequestError", () => HTTP request error), Match.tag("ResponseError", () => HTTP response error), Match.exhaustive, )} ), onNone: () => <>, }) }