Some checks failed
CI / E2E Tests (pull_request) Has been cancelled
CI / Unit & Component Tests (push) Successful in 2m30s
CI / Backend Unit Tests (push) Successful in 2m15s
CI / E2E Tests (push) Successful in 22m47s
CI / Unit & Component Tests (pull_request) Has been cancelled
CI / Backend Unit Tests (pull_request) Has been cancelled
- Add aria-label="Kommentare anzeigen" to annotation container div so
getByRole('button', { name: /annotation löschen/i }) no longer
matches the container (its name was previously inherited from the
child delete button, causing the test to click the wrong element)
- Wrap the server-side comments fetch in a .catch and try/catch so a
network error or non-JSON response never crashes the document load
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
34 lines
1003 B
TypeScript
34 lines
1003 B
TypeScript
import { error, redirect } from '@sveltejs/kit';
|
|
import { env } from '$env/dynamic/private';
|
|
import { createApiClient } from '$lib/api.server';
|
|
import { getErrorMessage } from '$lib/errors';
|
|
|
|
export async function load({ params, fetch }) {
|
|
const { id } = params;
|
|
const api = createApiClient(fetch);
|
|
const base = env.API_INTERNAL_URL || 'http://localhost:8080';
|
|
|
|
const [docResult, commentsRes] = await Promise.all([
|
|
api.GET('/api/documents/{id}', { params: { path: { id } } }),
|
|
fetch(`${base}/api/documents/${id}/comments`).catch(() => null)
|
|
]);
|
|
|
|
if (docResult.response.status === 401) throw redirect(302, '/login');
|
|
|
|
if (!docResult.response.ok) {
|
|
const code = (docResult.error as unknown as { code?: string })?.code;
|
|
throw error(docResult.response.status, getErrorMessage(code));
|
|
}
|
|
|
|
let comments: unknown[] = [];
|
|
if (commentsRes?.ok) {
|
|
try {
|
|
comments = await commentsRes.json();
|
|
} catch {
|
|
// ignore invalid response
|
|
}
|
|
}
|
|
|
|
return { document: docResult.data!, comments };
|
|
}
|