mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-01 17:39:39 +02:00
Tap client RPC acquisition causes
This commit is contained in:
parent
f7f29c4df9
commit
461b04d064
2 changed files with 40 additions and 20 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { Context, Effect, Layer, ManagedRuntime, Stream } from "effect";
|
||||
import { Cause, Context, Effect, Layer, ManagedRuntime, Stream } from "effect";
|
||||
import type * as RpcGroup from "effect/unstable/rpc/RpcGroup";
|
||||
import * as RpcClient from "effect/unstable/rpc/RpcClient";
|
||||
import type { RpcClientError } from "effect/unstable/rpc/RpcClientError";
|
||||
|
|
@ -128,13 +128,18 @@ export function makeEffectRpcClient(
|
|||
};
|
||||
|
||||
const runtime = ManagedRuntime.make(makeClientLayer());
|
||||
const clientPromise = runtime.runPromise(TrustGraphRpcClientService);
|
||||
clientPromise.catch((cause) => {
|
||||
setState({
|
||||
status: "failed",
|
||||
lastError: errorMessage(cause),
|
||||
});
|
||||
});
|
||||
const clientPromise = runtime.runPromise(
|
||||
TrustGraphRpcClientService.pipe(
|
||||
Effect.tapCause((cause) =>
|
||||
Effect.sync(() => {
|
||||
setState({
|
||||
status: "failed",
|
||||
lastError: Cause.pretty(cause),
|
||||
});
|
||||
})
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return {
|
||||
subscribe: (listener) => {
|
||||
|
|
@ -200,16 +205,6 @@ export function withDispatchRequestPolicy<A, E, R>(
|
|||
return retryTimes > 0 ? timed.pipe(Effect.retry({ times: retryTimes })) : timed;
|
||||
}
|
||||
|
||||
function errorMessage(cause: unknown): string {
|
||||
if (cause instanceof Error) return cause.message;
|
||||
if (typeof cause === "string") return cause;
|
||||
if (cause !== null && typeof cause === "object" && "message" in cause) {
|
||||
const message = (cause as { message?: unknown }).message;
|
||||
if (typeof message === "string") return message;
|
||||
}
|
||||
return String(cause);
|
||||
}
|
||||
|
||||
function normalizeTimeoutMs(timeoutMs: number | undefined): number {
|
||||
if (timeoutMs === undefined || !Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
||||
return DEFAULT_REQUEST_TIMEOUT_MS;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue