Skip to content
Source
Sign inSign up
TanStack/schemas
Open History to see the last commit

byteplus-docs.ts

22 lines794 Bytes

1import { fetchText } from './types.ts'
2​
3const SHELL_ATTEMPTS = 3
4​
5/**
6 * A docs.byteplus.com page as rendered HTML. Some fetches get the doc
7 * center's client-render shell instead: no `window._ROUTER_DATA`, the SSR
8 * slots left as `<!--<?- html ?>-->`. A refetch usually gets the rendered
9 * page, so the shell is retried; a page that is still the shell after the
10 * last attempt throws. HTTP errors are not retried.
11 */
12export async function fetchByteplusDoc(url: string): Promise<string> {
13 for (let attempt = 1; ; attempt++) {
14 const html = await fetchText(url)
15 if (html.includes('window._ROUTER_DATA')) return html
16 if (attempt === SHELL_ATTEMPTS) {
17 throw new Error(
18 `${url}: served the unrendered page shell ${String(SHELL_ATTEMPTS)} times`,
19 )
20 }
21 }