MCPcopy Create free account
hub / github.com/GitbookIO/gitbook / fetchFilesystem

Function fetchFilesystem

packages/gitbook/src/lib/openapi/fetch.ts:60–92  ·  view source on GitHub ↗

* Fetch the filesystem from the URL. * It's used for legacy "swagger" blocks.

(
    url: string,
    spaceId: string
)

Source from the content-addressed store, hash-verified

58 * It's used for legacy "swagger" blocks.
59 */
60async function fetchFilesystem(
61 url: string,
62 spaceId: string
63): Promise<
64 | Filesystem
65 | {
66 error: {
67 code: OpenAPIParseErrorCode;
68 message: string;
69 };
70 }
71> {
72 'use cache';
73 try {
74 cacheTag(getCacheTag({ tag: 'space', space: spaceId }));
75 return await fetchFilesystemNoCache(url);
76 } catch (error) {
77 // To avoid hammering the file with requests, we cache the error for around a minute.
78 cacheLife('minutes');
79 // Throwing an error inside a "use cache" function obfuscates the error,
80 // so we need to handle it here and recreates the error outside the cache function.
81 if (error instanceof OpenAPIParseError) {
82 return { error: { code: error.code, message: error.message } };
83 }
84 if (error instanceof DataFetcherError) {
85 return { error: { code: 'invalid' as const, message: 'Failed to fetch OpenAPI file' } };
86 }
87 // If the error is not an OpenAPIParseError or DataFetcherError,
88 // we assume it's an unknown error and return a generic error.
89 console.error('Unknown error while fetching OpenAPI file:', error);
90 return { error: { code: 'invalid' as const, message: 'Unknown error' } };
91 }
92}
93
94async function fetchFilesystemNoCache(url: string) {
95 console.log(url);

Callers 1

fetchOpenAPIFilesystemFunction · 0.70

Calls 2

getCacheTagFunction · 0.90
fetchFilesystemNoCacheFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…