20 lines
716 B
TypeScript
20 lines
716 B
TypeScript
import { error, redirect } from '@sveltejs/kit';
|
|
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
|
|
import { getErrorMessage } from '$lib/shared/errors';
|
|
import type { PageServerLoad } from './$types';
|
|
|
|
export const load: PageServerLoad = async ({ params, fetch, parent }) => {
|
|
const layout = await parent();
|
|
if (!layout.canBlogWrite) {
|
|
throw redirect(303, `/geschichten/${params.id}`);
|
|
}
|
|
const api = createApiClient(fetch);
|
|
const result = await api.GET('/api/geschichten/{id}', {
|
|
params: { path: { id: params.id } }
|
|
});
|
|
if (!result.response.ok) {
|
|
throw error(result.response.status, getErrorMessage(extractErrorCode(result.error)));
|
|
}
|
|
return { geschichte: result.data! };
|
|
};
|