We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 618e121 + 6f0bbfe commit 5e96736Copy full SHA for 5e96736
1 file changed
packages/sdk/src/hooks/networkHooks.ts
@@ -0,0 +1,20 @@
1
+import type { StellarExplainError } from "../errors";
2
+
3
+export interface NetworkHooks {
4
+ onRequest?: (url: string) => void;
5
+ onResponse?: (url: string, status: number, durationMs: number) => void;
6
+ onError?: (url: string, error: StellarExplainError) => void;
7
+ onCacheHit?: (key: string) => void;
8
+}
9
10
+export function callHook<T extends (...args: never[]) => void>(
11
+ hook: T | undefined,
12
+ ...args: Parameters<T>
13
+): void {
14
+ if (!hook) return;
15
+ try {
16
+ hook(...args);
17
+ } catch {
18
+ // hooks must never propagate errors to the consumer
19
+ }
20
0 commit comments