mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
feat(spf): multi cdn failover (#1671)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
33873bc4ae
commit
b89f1e944c
@@ -124,6 +124,23 @@ export function getResponseText(response: ResponseLike): Promise<string> {
|
||||
return response.text();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a resource and resolve its text body — the text analog of
|
||||
* {@link FetchBytes}. A non-OK status rejects, so HTTP failures surface as
|
||||
* rejections that callers (and decorators like the failover tracker) handle
|
||||
* uniformly with network errors.
|
||||
*/
|
||||
export type FetchText = (addressable: Resource, options?: RequestInit) => Promise<string>;
|
||||
|
||||
/** Default {@link FetchText}: fetch the resource, reject on non-OK, return text. */
|
||||
export const fetchResolvableText: FetchText = async (addressable, options) => {
|
||||
const response = await fetchResolvable(addressable, options);
|
||||
if (!response.ok) {
|
||||
throw new Error(`fetchResolvableText: ${response.status} ${response.statusText} for ${addressable.url}`);
|
||||
}
|
||||
return getResponseText(response);
|
||||
};
|
||||
|
||||
/**
|
||||
* Two-stage fetch helper: eagerly starts the HTTP request (TTFB is awaited),
|
||||
* then returns a lazy iterable over the response body. Separating connection
|
||||
|
||||
Reference in New Issue
Block a user