* Fetch the filesystem from the URL. * It's used for legacy "swagger" blocks.
(
url: string,
spaceId: string
)
| 58 | * It's used for legacy "swagger" blocks. |
| 59 | */ |
| 60 | async 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 | |
| 94 | async function fetchFilesystemNoCache(url: string) { |
| 95 | console.log(url); |
no test coverage detected
searching dependent graphs…