Skip to content

Commit 5e96736

Browse files
authored
Merge pull request #253 from Leothosine/feat/sdk-network-hooks
feat(sdk): add network event hooks (onRequest, onResponse, onError)
2 parents 618e121 + 6f0bbfe commit 5e96736

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)