(
project: string,
options: LayoutSourceOptions = {},
)
| 149 | * Flaechen dieses Servers gerade schweigt. |
| 150 | */ |
| 151 | export async function loadLayout( |
| 152 | project: string, |
| 153 | options: LayoutSourceOptions = {}, |
| 154 | ): Promise<GraphData> { |
| 155 | const route = layoutUrl(project, options.maxNodes ?? LAYOUT_NODE_BUDGET); |
| 156 | const url = `${options.base ?? ''}${route}`; |
| 157 | const doFetch = options.fetch ?? globalThis.fetch; |
| 158 | let response: Response; |
| 159 | try { |
| 160 | response = await doFetch(url, { |
| 161 | headers: { Accept: 'application/json' }, |
| 162 | ...(options.signal !== undefined ? { signal: options.signal } : {}), |
| 163 | }); |
| 164 | } catch (error) { |
| 165 | const message = error instanceof Error ? error.message : String(error); |
| 166 | throw new LayoutError(0, `${LAYOUT_ROUTE} war nicht erreichbar: ${message}`); |
| 167 | } |
| 168 | const body = await response.text(); |
| 169 | if (!response.ok) { |
| 170 | throw new LayoutError( |
| 171 | response.status, |
| 172 | `${LAYOUT_ROUTE} antwortete mit HTTP ${response.status}: ${body.slice(0, 200)}`, |
| 173 | ); |
| 174 | } |
| 175 | let parsed: unknown; |
| 176 | try { |
| 177 | parsed = JSON.parse(body) as unknown; |
| 178 | } catch { |
| 179 | throw new LayoutError(response.status, `${LAYOUT_ROUTE} lieferte kein JSON: ${body.slice(0, 200)}`); |
| 180 | } |
| 181 | return readGraphData(parsed); |
| 182 | } |
no test coverage detected