Compare commits
4 Commits
feat/issue
...
feat/issue
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb69135f2c | ||
|
|
4edd2461d1 | ||
|
|
fc9a02a6a0 | ||
|
|
6607ad9104 |
20
frontend/src/lib/shared/api.server.spec.ts
Normal file
20
frontend/src/lib/shared/api.server.spec.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { describe, it, expect } from 'vitest';
|
||||||
|
import { extractErrorCode } from './api.server';
|
||||||
|
|
||||||
|
describe('extractErrorCode', () => {
|
||||||
|
it('returns the code string when error has a code property', () => {
|
||||||
|
expect(extractErrorCode({ code: 'DOCUMENT_NOT_FOUND' })).toBe('DOCUMENT_NOT_FOUND');
|
||||||
|
});
|
||||||
|
it('returns undefined when error is undefined', () => {
|
||||||
|
expect(extractErrorCode(undefined)).toBeUndefined();
|
||||||
|
});
|
||||||
|
it('returns undefined when error is null', () => {
|
||||||
|
expect(extractErrorCode(null)).toBeUndefined();
|
||||||
|
});
|
||||||
|
it('returns undefined when error is a plain string', () => {
|
||||||
|
expect(extractErrorCode('oops')).toBeUndefined();
|
||||||
|
});
|
||||||
|
it('returns undefined when error object has no code property', () => {
|
||||||
|
expect(extractErrorCode({ message: 'fail' })).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -23,3 +23,11 @@ export function createApiClient(fetch: typeof globalThis.fetch) {
|
|||||||
fetch
|
fetch
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ApiError {
|
||||||
|
code?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function extractErrorCode(error: unknown): string | undefined {
|
||||||
|
return (error as ApiError | undefined)?.code;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
import { env } from '$env/dynamic/private';
|
import { env } from '$env/dynamic/private';
|
||||||
import { createApiClient } from '$lib/shared/api.server';
|
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
|
||||||
import { getErrorMessage } from '$lib/shared/errors';
|
import { getErrorMessage } from '$lib/shared/errors';
|
||||||
import type { components } from '$lib/generated/api';
|
import type { components } from '$lib/generated/api';
|
||||||
|
|
||||||
@@ -34,16 +34,16 @@ export async function load({ fetch, locals }) {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if (!usersResult.response.ok) {
|
if (!usersResult.response.ok) {
|
||||||
const code = (usersResult.error as unknown as { code?: string })?.code;
|
throw error(usersResult.response.status, getErrorMessage(extractErrorCode(usersResult.error)));
|
||||||
throw error(usersResult.response.status, getErrorMessage(code));
|
|
||||||
}
|
}
|
||||||
if (!groupsResult.response.ok) {
|
if (!groupsResult.response.ok) {
|
||||||
const code = (groupsResult.error as unknown as { code?: string })?.code;
|
throw error(
|
||||||
throw error(groupsResult.response.status, getErrorMessage(code));
|
groupsResult.response.status,
|
||||||
|
getErrorMessage(extractErrorCode(groupsResult.error))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (!tagsResult.response.ok) {
|
if (!tagsResult.response.ok) {
|
||||||
const code = (tagsResult.error as unknown as { code?: string })?.code;
|
throw error(tagsResult.response.status, getErrorMessage(extractErrorCode(tagsResult.error)));
|
||||||
throw error(tagsResult.response.status, getErrorMessage(code));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let inviteCount = 0;
|
let inviteCount = 0;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { error, fail, redirect } from '@sveltejs/kit';
|
import { error, fail, redirect } from '@sveltejs/kit';
|
||||||
import type { PageServerLoad, Actions } from './$types';
|
import type { PageServerLoad, Actions } from './$types';
|
||||||
import { createApiClient } from '$lib/shared/api.server';
|
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
|
||||||
import { getErrorMessage } from '$lib/shared/errors';
|
import { getErrorMessage } from '$lib/shared/errors';
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ params, parent }) => {
|
export const load: PageServerLoad = async ({ params, parent }) => {
|
||||||
@@ -24,8 +24,9 @@ export const actions: Actions = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
return fail(result.response.status, {
|
||||||
return fail(result.response.status, { error: getErrorMessage(code) });
|
error: getErrorMessage(extractErrorCode(result.error))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return { success: true };
|
return { success: true };
|
||||||
@@ -38,8 +39,9 @@ export const actions: Actions = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
return fail(result.response.status, {
|
||||||
return fail(result.response.status, { error: getErrorMessage(code) });
|
error: getErrorMessage(extractErrorCode(result.error))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
throw redirect(303, '/admin/groups');
|
throw redirect(303, '/admin/groups');
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { fail, redirect } from '@sveltejs/kit';
|
import { fail, redirect } from '@sveltejs/kit';
|
||||||
import type { Actions } from './$types';
|
import type { Actions } from './$types';
|
||||||
import { createApiClient } from '$lib/shared/api.server';
|
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
|
||||||
import { getErrorMessage } from '$lib/shared/errors';
|
import { getErrorMessage } from '$lib/shared/errors';
|
||||||
|
|
||||||
export const actions: Actions = {
|
export const actions: Actions = {
|
||||||
@@ -16,8 +16,9 @@ export const actions: Actions = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
return fail(result.response.status, {
|
||||||
return fail(result.response.status, { error: getErrorMessage(code) });
|
error: getErrorMessage(extractErrorCode(result.error))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
throw redirect(303, '/admin/groups');
|
throw redirect(303, '/admin/groups');
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { fail } from '@sveltejs/kit';
|
import { fail } from '@sveltejs/kit';
|
||||||
import { createApiClient } from '$lib/shared/api.server';
|
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
|
||||||
import { getErrorMessage } from '$lib/shared/errors';
|
import { getErrorMessage } from '$lib/shared/errors';
|
||||||
import type { Actions, PageServerLoad } from './$types';
|
import type { Actions, PageServerLoad } from './$types';
|
||||||
import type { components } from '$lib/generated/api';
|
import type { components } from '$lib/generated/api';
|
||||||
@@ -25,8 +25,7 @@ export const load: PageServerLoad = async ({ url, fetch }) => {
|
|||||||
let invites: InviteListItem[] = [];
|
let invites: InviteListItem[] = [];
|
||||||
let loadError: string | null = null;
|
let loadError: string | null = null;
|
||||||
if (!invitesResult.response.ok) {
|
if (!invitesResult.response.ok) {
|
||||||
const code = (invitesResult.error as unknown as { code?: string })?.code;
|
loadError = extractErrorCode(invitesResult.error) ?? 'INTERNAL_ERROR';
|
||||||
loadError = code ?? 'INTERNAL_ERROR';
|
|
||||||
} else {
|
} else {
|
||||||
invites = (invitesResult.data ?? []) as InviteListItem[];
|
invites = (invitesResult.data ?? []) as InviteListItem[];
|
||||||
}
|
}
|
||||||
@@ -34,8 +33,7 @@ export const load: PageServerLoad = async ({ url, fetch }) => {
|
|||||||
let groups: UserGroup[] = [];
|
let groups: UserGroup[] = [];
|
||||||
let groupsLoadError: string | null = null;
|
let groupsLoadError: string | null = null;
|
||||||
if (!groupsResult.response.ok) {
|
if (!groupsResult.response.ok) {
|
||||||
const code = (groupsResult.error as unknown as { code?: string })?.code;
|
groupsLoadError = extractErrorCode(groupsResult.error) ?? 'INTERNAL_ERROR';
|
||||||
groupsLoadError = code ?? 'INTERNAL_ERROR';
|
|
||||||
} else {
|
} else {
|
||||||
const raw = groupsResult.data ?? [];
|
const raw = groupsResult.data ?? [];
|
||||||
groups = [...raw].sort((a, b) => a.name.localeCompare(b.name));
|
groups = [...raw].sort((a, b) => a.name.localeCompare(b.name));
|
||||||
@@ -62,8 +60,9 @@ export const actions = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
return fail(result.response.status, {
|
||||||
return fail(result.response.status, { createError: code ?? 'INTERNAL_ERROR' });
|
createError: extractErrorCode(result.error) ?? 'INTERNAL_ERROR'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return { created: result.data! as InviteListItem };
|
return { created: result.data! as InviteListItem };
|
||||||
@@ -78,8 +77,9 @@ export const actions = {
|
|||||||
const result = await api.DELETE('/api/invites/{id}', { params: { path: { id } } });
|
const result = await api.DELETE('/api/invites/{id}', { params: { path: { id } } });
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
return fail(result.response.status, {
|
||||||
return fail(result.response.status, { revokeError: code ?? 'INTERNAL_ERROR' });
|
revokeError: extractErrorCode(result.error) ?? 'INTERNAL_ERROR'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return { revoked: id };
|
return { revoked: id };
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
import { createApiClient } from '$lib/shared/api.server';
|
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
|
||||||
import { getErrorMessage } from '$lib/shared/errors';
|
import { getErrorMessage } from '$lib/shared/errors';
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ fetch }) => {
|
export const load: PageServerLoad = async ({ fetch }) => {
|
||||||
@@ -8,8 +8,7 @@ export const load: PageServerLoad = async ({ fetch }) => {
|
|||||||
const result = await api.GET('/api/ocr/training-info');
|
const result = await api.GET('/api/ocr/training-info');
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
throw error(result.response.status, getErrorMessage(extractErrorCode(result.error)));
|
||||||
throw error(result.response.status, getErrorMessage(code));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { trainingInfo: result.data! };
|
return { trainingInfo: result.data! };
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
import { createApiClient } from '$lib/shared/api.server';
|
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
|
||||||
import { getErrorMessage } from '$lib/shared/errors';
|
import { getErrorMessage } from '$lib/shared/errors';
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ params, fetch }) => {
|
export const load: PageServerLoad = async ({ params, fetch }) => {
|
||||||
@@ -10,8 +10,7 @@ export const load: PageServerLoad = async ({ params, fetch }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
throw error(result.response.status, getErrorMessage(extractErrorCode(result.error)));
|
||||||
throw error(result.response.status, getErrorMessage(code));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { history: result.data!, personId: params.personId };
|
return { history: result.data!, personId: params.personId };
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
import { createApiClient } from '$lib/shared/api.server';
|
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
|
||||||
import { getErrorMessage } from '$lib/shared/errors';
|
import { getErrorMessage } from '$lib/shared/errors';
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ fetch }) => {
|
export const load: PageServerLoad = async ({ fetch }) => {
|
||||||
@@ -8,8 +8,7 @@ export const load: PageServerLoad = async ({ fetch }) => {
|
|||||||
const result = await api.GET('/api/ocr/training-info/global');
|
const result = await api.GET('/api/ocr/training-info/global');
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
throw error(result.response.status, getErrorMessage(extractErrorCode(result.error)));
|
||||||
throw error(result.response.status, getErrorMessage(code));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { history: result.data! };
|
return { history: result.data! };
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { error, fail, redirect } from '@sveltejs/kit';
|
import { error, fail, redirect } from '@sveltejs/kit';
|
||||||
import type { PageServerLoad, Actions } from './$types';
|
import type { PageServerLoad, Actions } from './$types';
|
||||||
import { createApiClient } from '$lib/shared/api.server';
|
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
|
||||||
import { getErrorMessage } from '$lib/shared/errors';
|
import { getErrorMessage } from '$lib/shared/errors';
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ params, parent, url }) => {
|
export const load: PageServerLoad = async ({ params, parent, url }) => {
|
||||||
@@ -25,8 +25,9 @@ export const actions: Actions = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
return fail(result.response.status, {
|
||||||
return fail(result.response.status, { error: getErrorMessage(code) });
|
error: getErrorMessage(extractErrorCode(result.error))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return { success: true };
|
return { success: true };
|
||||||
@@ -43,8 +44,9 @@ export const actions: Actions = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
return fail(result.response.status, {
|
||||||
return fail(result.response.status, { error: getErrorMessage(code) });
|
error: getErrorMessage(extractErrorCode(result.error))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
throw redirect(303, `/admin/tags/${result.data!.id}?merged=1`);
|
throw redirect(303, `/admin/tags/${result.data!.id}?merged=1`);
|
||||||
@@ -65,8 +67,9 @@ export const actions: Actions = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
return fail(result.response.status, {
|
||||||
return fail(result.response.status, { error: getErrorMessage(code) });
|
error: getErrorMessage(extractErrorCode(result.error))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
throw redirect(303, '/admin/tags');
|
throw redirect(303, '/admin/tags');
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { error, fail, redirect } from '@sveltejs/kit';
|
import { error, fail, redirect } from '@sveltejs/kit';
|
||||||
import type { PageServerLoad, Actions } from './$types';
|
import type { PageServerLoad, Actions } from './$types';
|
||||||
import { createApiClient } from '$lib/shared/api.server';
|
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
|
||||||
import { getErrorMessage } from '$lib/shared/errors';
|
import { getErrorMessage } from '$lib/shared/errors';
|
||||||
import type { components } from '$lib/generated/api';
|
import type { components } from '$lib/generated/api';
|
||||||
|
|
||||||
@@ -55,8 +55,9 @@ export const actions: Actions = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
return fail(result.response.status, {
|
||||||
return fail(result.response.status, { error: getErrorMessage(code) });
|
error: getErrorMessage(extractErrorCode(result.error))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return { success: true };
|
return { success: true };
|
||||||
@@ -69,8 +70,9 @@ export const actions: Actions = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
return fail(result.response.status, {
|
||||||
return fail(result.response.status, { error: getErrorMessage(code) });
|
error: getErrorMessage(extractErrorCode(result.error))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
throw redirect(303, '/admin/users');
|
throw redirect(303, '/admin/users');
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { error, fail, redirect } from '@sveltejs/kit';
|
import { error, fail, redirect } from '@sveltejs/kit';
|
||||||
import type { PageServerLoad, Actions } from './$types';
|
import type { PageServerLoad, Actions } from './$types';
|
||||||
import { createApiClient } from '$lib/shared/api.server';
|
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
|
||||||
import { getErrorMessage } from '$lib/shared/errors';
|
import { getErrorMessage } from '$lib/shared/errors';
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ fetch, locals }) => {
|
export const load: PageServerLoad = async ({ fetch, locals }) => {
|
||||||
@@ -35,8 +35,9 @@ export const actions: Actions = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
return fail(result.response.status, {
|
||||||
return fail(result.response.status, { error: getErrorMessage(code) });
|
error: getErrorMessage(extractErrorCode(result.error))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
throw redirect(303, '/admin/users');
|
throw redirect(303, '/admin/users');
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
import type { components } from '$lib/generated/api';
|
import type { components } from '$lib/generated/api';
|
||||||
import { createApiClient } from '$lib/shared/api.server';
|
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
|
||||||
import { getErrorMessage } from '$lib/shared/errors';
|
import { getErrorMessage } from '$lib/shared/errors';
|
||||||
|
|
||||||
export async function load({ url, fetch, locals }) {
|
export async function load({ url, fetch, locals }) {
|
||||||
@@ -39,8 +39,7 @@ export async function load({ url, fetch, locals }) {
|
|||||||
})
|
})
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
throw error(result.response.status, getErrorMessage(extractErrorCode(result.error)));
|
||||||
throw error(result.response.status, getErrorMessage(code));
|
|
||||||
}
|
}
|
||||||
documents = result.data ?? [];
|
documents = result.data ?? [];
|
||||||
})
|
})
|
||||||
@@ -49,8 +48,7 @@ export async function load({ url, fetch, locals }) {
|
|||||||
requests.push(
|
requests.push(
|
||||||
api.GET('/api/persons/{id}', { params: { path: { id: senderId } } }).then((result) => {
|
api.GET('/api/persons/{id}', { params: { path: { id: senderId } } }).then((result) => {
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
throw error(result.response.status, getErrorMessage(extractErrorCode(result.error)));
|
||||||
throw error(result.response.status, getErrorMessage(code));
|
|
||||||
}
|
}
|
||||||
const p = result.data as { displayName: string } | undefined;
|
const p = result.data as { displayName: string } | undefined;
|
||||||
if (p) senderName = p.displayName;
|
if (p) senderName = p.displayName;
|
||||||
@@ -62,8 +60,7 @@ export async function load({ url, fetch, locals }) {
|
|||||||
requests.push(
|
requests.push(
|
||||||
api.GET('/api/persons/{id}', { params: { path: { id: receiverId } } }).then((result) => {
|
api.GET('/api/persons/{id}', { params: { path: { id: receiverId } } }).then((result) => {
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
throw error(result.response.status, getErrorMessage(extractErrorCode(result.error)));
|
||||||
throw error(result.response.status, getErrorMessage(code));
|
|
||||||
}
|
}
|
||||||
const p = result.data as { displayName: string } | undefined;
|
const p = result.data as { displayName: string } | undefined;
|
||||||
if (p) receiverName = p.displayName;
|
if (p) receiverName = p.displayName;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { redirect } from '@sveltejs/kit';
|
import { redirect } from '@sveltejs/kit';
|
||||||
import { createApiClient } from '$lib/shared/api.server';
|
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
|
||||||
import { getErrorMessage } from '$lib/shared/errors';
|
import { getErrorMessage } from '$lib/shared/errors';
|
||||||
import type { components } from '$lib/generated/api';
|
import type { components } from '$lib/generated/api';
|
||||||
|
|
||||||
@@ -103,8 +103,7 @@ export async function load({ url, fetch }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const errorMessage: string | null = !result.response.ok
|
const errorMessage: string | null = !result.response.ok
|
||||||
? (getErrorMessage((result.error as unknown as { code?: string })?.code) ??
|
? (getErrorMessage(extractErrorCode(result.error)) ?? 'Daten konnten nicht geladen werden.')
|
||||||
'Daten konnten nicht geladen werden.')
|
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { error, redirect } from '@sveltejs/kit';
|
import { error, redirect } from '@sveltejs/kit';
|
||||||
import { createApiClient } from '$lib/shared/api.server';
|
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
|
||||||
import { getErrorMessage } from '$lib/shared/errors';
|
import { getErrorMessage } from '$lib/shared/errors';
|
||||||
import { inferredRelationshipLabel } from '$lib/person/relationshipLabels';
|
import { inferredRelationshipLabel } from '$lib/person/relationshipLabels';
|
||||||
|
|
||||||
@@ -17,8 +17,7 @@ export async function load({ params, fetch }) {
|
|||||||
if (docResult.response.status === 401) throw redirect(302, '/login');
|
if (docResult.response.status === 401) throw redirect(302, '/login');
|
||||||
|
|
||||||
if (!docResult.response.ok) {
|
if (!docResult.response.ok) {
|
||||||
const code = (docResult.error as unknown as { code?: string })?.code;
|
throw error(docResult.response.status, getErrorMessage(extractErrorCode(docResult.error)));
|
||||||
throw error(docResult.response.status, getErrorMessage(code));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const document = docResult.data!;
|
const document = docResult.data!;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { error, fail, redirect } from '@sveltejs/kit';
|
import { error, fail, redirect } from '@sveltejs/kit';
|
||||||
import { env } from '$env/dynamic/private';
|
import { env } from '$env/dynamic/private';
|
||||||
import { createApiClient } from '$lib/shared/api.server';
|
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
|
||||||
import { parseBackendError, getErrorMessage } from '$lib/shared/errors';
|
import { parseBackendError, getErrorMessage } from '$lib/shared/errors';
|
||||||
|
|
||||||
export async function load({
|
export async function load({
|
||||||
@@ -30,8 +30,7 @@ export async function load({
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if (!docResult.response.ok) {
|
if (!docResult.response.ok) {
|
||||||
const code = (docResult.error as unknown as { code?: string })?.code;
|
throw error(docResult.response.status, getErrorMessage(extractErrorCode(docResult.error)));
|
||||||
throw error(docResult.response.status, getErrorMessage(code));
|
|
||||||
}
|
}
|
||||||
if (!personsResult.response.ok) {
|
if (!personsResult.response.ok) {
|
||||||
throw error(personsResult.response.status, getErrorMessage('INTERNAL_ERROR'));
|
throw error(personsResult.response.status, getErrorMessage('INTERNAL_ERROR'));
|
||||||
@@ -76,8 +75,9 @@ export const actions = {
|
|||||||
// Fetch current document to preserve all existing fields
|
// Fetch current document to preserve all existing fields
|
||||||
const docResult = await api.GET('/api/documents/{id}', { params: { path: { id: params.id } } });
|
const docResult = await api.GET('/api/documents/{id}', { params: { path: { id: params.id } } });
|
||||||
if (!docResult.response.ok) {
|
if (!docResult.response.ok) {
|
||||||
const code = (docResult.error as unknown as { code?: string })?.code;
|
return fail(docResult.response.status, {
|
||||||
return fail(docResult.response.status, { error: getErrorMessage(code) });
|
error: getErrorMessage(extractErrorCode(docResult.error))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const doc = docResult.data!;
|
const doc = docResult.data!;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { error, redirect } from '@sveltejs/kit';
|
import { error, redirect } from '@sveltejs/kit';
|
||||||
import { env } from '$env/dynamic/private';
|
import { env } from '$env/dynamic/private';
|
||||||
import { createApiClient } from '$lib/shared/api.server';
|
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
|
||||||
import { getErrorMessage, parseBackendError } from '$lib/shared/errors';
|
import { getErrorMessage, parseBackendError } from '$lib/shared/errors';
|
||||||
|
|
||||||
export async function load({
|
export async function load({
|
||||||
@@ -31,8 +31,7 @@ export async function load({
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if (!docResult.response.ok) {
|
if (!docResult.response.ok) {
|
||||||
const code = (docResult.error as unknown as { code?: string })?.code;
|
throw error(docResult.response.status, getErrorMessage(extractErrorCode(docResult.error)));
|
||||||
throw error(docResult.response.status, getErrorMessage(code));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const incompleteCount = countResult.response.ok ? (countResult.data?.count ?? 0) : 0;
|
const incompleteCount = countResult.response.ok ? (countResult.data?.count ?? 0) : 0;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
import { createApiClient } from '$lib/shared/api.server';
|
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
|
||||||
import { getErrorMessage } from '$lib/shared/errors';
|
import { getErrorMessage } from '$lib/shared/errors';
|
||||||
import type { components } from '$lib/generated/api';
|
import type { components } from '$lib/generated/api';
|
||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
@@ -25,8 +25,7 @@ export const load: PageServerLoad = async ({ url, fetch }) => {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if (!listResult.response.ok) {
|
if (!listResult.response.ok) {
|
||||||
const code = (listResult.error as unknown as { code?: string })?.code;
|
throw error(listResult.response.status, getErrorMessage(extractErrorCode(listResult.error)));
|
||||||
throw error(listResult.response.status, getErrorMessage(code));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const personFilters = personResults
|
const personFilters = personResults
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
import { createApiClient } from '$lib/shared/api.server';
|
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
|
||||||
import { getErrorMessage } from '$lib/shared/errors';
|
import { getErrorMessage } from '$lib/shared/errors';
|
||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
|
|
||||||
@@ -9,8 +9,7 @@ export const load: PageServerLoad = async ({ params, fetch }) => {
|
|||||||
params: { path: { id: params.id } }
|
params: { path: { id: params.id } }
|
||||||
});
|
});
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
throw error(result.response.status, getErrorMessage(extractErrorCode(result.error)));
|
||||||
throw error(result.response.status, getErrorMessage(code));
|
|
||||||
}
|
}
|
||||||
return { geschichte: result.data! };
|
return { geschichte: result.data! };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { error, redirect } from '@sveltejs/kit';
|
import { error, redirect } from '@sveltejs/kit';
|
||||||
import { createApiClient } from '$lib/shared/api.server';
|
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
|
||||||
import { getErrorMessage } from '$lib/shared/errors';
|
import { getErrorMessage } from '$lib/shared/errors';
|
||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
|
|
||||||
@@ -13,8 +13,7 @@ export const load: PageServerLoad = async ({ params, fetch, parent }) => {
|
|||||||
params: { path: { id: params.id } }
|
params: { path: { id: params.id } }
|
||||||
});
|
});
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
throw error(result.response.status, getErrorMessage(extractErrorCode(result.error)));
|
||||||
throw error(result.response.status, getErrorMessage(code));
|
|
||||||
}
|
}
|
||||||
return { geschichte: result.data! };
|
return { geschichte: result.data! };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
import { createApiClient } from '$lib/shared/api.server';
|
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
|
||||||
import { getErrorMessage } from '$lib/shared/errors';
|
import { getErrorMessage } from '$lib/shared/errors';
|
||||||
|
|
||||||
export async function load({ params, fetch, locals }) {
|
export async function load({ params, fetch, locals }) {
|
||||||
@@ -32,8 +32,10 @@ export async function load({ params, fetch, locals }) {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if (!personResult.response.ok) {
|
if (!personResult.response.ok) {
|
||||||
const code = (personResult.error as unknown as { code?: string })?.code;
|
throw error(
|
||||||
throw error(personResult.response.status, getErrorMessage(code));
|
personResult.response.status,
|
||||||
|
getErrorMessage(extractErrorCode(personResult.error))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { error, fail, redirect } from '@sveltejs/kit';
|
import { error, fail, redirect } from '@sveltejs/kit';
|
||||||
import { createApiClient } from '$lib/shared/api.server';
|
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
|
||||||
import { getErrorMessage } from '$lib/shared/errors';
|
import { getErrorMessage } from '$lib/shared/errors';
|
||||||
import {
|
import {
|
||||||
normalizePersonType,
|
normalizePersonType,
|
||||||
@@ -25,8 +25,7 @@ export async function load({ params, fetch, locals }) {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
throw error(result.response.status, getErrorMessage(extractErrorCode(result.error)));
|
||||||
throw error(result.response.status, getErrorMessage(code));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const person = result.data!;
|
const person = result.data!;
|
||||||
@@ -74,8 +73,9 @@ export const actions = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
return fail(result.response.status, {
|
||||||
return fail(result.response.status, { updateError: getErrorMessage(code) });
|
updateError: getErrorMessage(extractErrorCode(result.error))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
throw redirect(303, `/persons/${params.id}`);
|
throw redirect(303, `/persons/${params.id}`);
|
||||||
@@ -100,8 +100,9 @@ export const actions = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
return fail(result.response.status, {
|
||||||
return fail(result.response.status, { mergeError: getErrorMessage(code) });
|
mergeError: getErrorMessage(extractErrorCode(result.error))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
throw redirect(303, `/persons/${targetPersonId}`);
|
throw redirect(303, `/persons/${targetPersonId}`);
|
||||||
@@ -127,8 +128,9 @@ export const actions = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
return fail(result.response.status, {
|
||||||
return fail(result.response.status, { aliasError: getErrorMessage(code) });
|
aliasError: getErrorMessage(extractErrorCode(result.error))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return { aliasSuccess: true };
|
return { aliasSuccess: true };
|
||||||
@@ -148,8 +150,9 @@ export const actions = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
return fail(result.response.status, {
|
||||||
return fail(result.response.status, { aliasError: getErrorMessage(code) });
|
aliasError: getErrorMessage(extractErrorCode(result.error))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return { aliasSuccess: true };
|
return { aliasSuccess: true };
|
||||||
@@ -166,8 +169,9 @@ export const actions = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
return fail(result.response.status, {
|
||||||
return fail(result.response.status, { relationshipError: getErrorMessage(code) });
|
relationshipError: getErrorMessage(extractErrorCode(result.error))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return { relationshipSuccess: true };
|
return { relationshipSuccess: true };
|
||||||
},
|
},
|
||||||
@@ -211,8 +215,9 @@ export const actions = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
return fail(result.response.status, {
|
||||||
return fail(result.response.status, { relationshipError: getErrorMessage(code) });
|
relationshipError: getErrorMessage(extractErrorCode(result.error))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return { relationshipSuccess: true };
|
return { relationshipSuccess: true };
|
||||||
},
|
},
|
||||||
@@ -230,8 +235,9 @@ export const actions = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
return fail(result.response.status, {
|
||||||
return fail(result.response.status, { relationshipError: getErrorMessage(code) });
|
relationshipError: getErrorMessage(extractErrorCode(result.error))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return { relationshipSuccess: true };
|
return { relationshipSuccess: true };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { error, fail, redirect } from '@sveltejs/kit';
|
import { error, fail, redirect } from '@sveltejs/kit';
|
||||||
import { createApiClient } from '$lib/shared/api.server';
|
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
|
||||||
import { getErrorMessage } from '$lib/shared/errors';
|
import { getErrorMessage } from '$lib/shared/errors';
|
||||||
import {
|
import {
|
||||||
normalizePersonType,
|
normalizePersonType,
|
||||||
@@ -57,9 +57,8 @@ export const actions = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
|
||||||
return fail(result.response.status, {
|
return fail(result.response.status, {
|
||||||
error: getErrorMessage(code),
|
error: getErrorMessage(extractErrorCode(result.error)),
|
||||||
personType,
|
personType,
|
||||||
title,
|
title,
|
||||||
firstName,
|
firstName,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { fail } from '@sveltejs/kit';
|
import { fail } from '@sveltejs/kit';
|
||||||
import { env } from '$env/dynamic/private';
|
import { env } from '$env/dynamic/private';
|
||||||
import type { PageServerLoad, Actions } from './$types';
|
import type { PageServerLoad, Actions } from './$types';
|
||||||
import { createApiClient } from '$lib/shared/api.server';
|
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
|
||||||
import { getErrorMessage } from '$lib/shared/errors';
|
import { getErrorMessage } from '$lib/shared/errors';
|
||||||
|
|
||||||
const apiBase = () => env.API_INTERNAL_URL || 'http://localhost:8080';
|
const apiBase = () => env.API_INTERNAL_URL || 'http://localhost:8080';
|
||||||
@@ -27,8 +27,9 @@ export const actions: Actions = {
|
|||||||
const result = await api.PUT('/api/users/me', { body });
|
const result = await api.PUT('/api/users/me', { body });
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
return fail(result.response.status, {
|
||||||
return fail(result.response.status, { updateError: getErrorMessage(code) });
|
updateError: getErrorMessage(extractErrorCode(result.error))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return { updateSuccess: true };
|
return { updateSuccess: true };
|
||||||
@@ -50,8 +51,9 @@ export const actions: Actions = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
return fail(result.response.status, {
|
||||||
return fail(result.response.status, { passwordError: getErrorMessage(code) });
|
passwordError: getErrorMessage(extractErrorCode(result.error))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return { passwordSuccess: true };
|
return { passwordSuccess: true };
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { error, redirect } from '@sveltejs/kit';
|
import { error, redirect } from '@sveltejs/kit';
|
||||||
import { createApiClient } from '$lib/shared/api.server';
|
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
|
||||||
import { getErrorMessage } from '$lib/shared/errors';
|
import { getErrorMessage } from '$lib/shared/errors';
|
||||||
|
|
||||||
export async function load({ fetch }) {
|
export async function load({ fetch }) {
|
||||||
@@ -9,8 +9,7 @@ export async function load({ fetch }) {
|
|||||||
if (result.response.status === 401) throw redirect(302, '/login');
|
if (result.response.status === 401) throw redirect(302, '/login');
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
throw error(result.response.status, getErrorMessage(extractErrorCode(result.error)));
|
||||||
throw error(result.response.status, getErrorMessage(code));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const network = result.data!;
|
const network = result.data!;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
import { createApiClient } from '$lib/shared/api.server';
|
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
|
||||||
import { getErrorMessage } from '$lib/shared/errors';
|
import { getErrorMessage } from '$lib/shared/errors';
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ params, fetch }) => {
|
export const load: PageServerLoad = async ({ params, fetch }) => {
|
||||||
@@ -8,8 +8,7 @@ export const load: PageServerLoad = async ({ params, fetch }) => {
|
|||||||
const result = await api.GET('/api/users/{id}', { params: { path: { id: params.id } } });
|
const result = await api.GET('/api/users/{id}', { params: { path: { id: params.id } } });
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
const code = (result.error as unknown as { code?: string })?.code;
|
throw error(result.response.status, getErrorMessage(extractErrorCode(result.error)));
|
||||||
throw error(result.response.status, getErrorMessage(code));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { profileUser: result.data! };
|
return { profileUser: result.data! };
|
||||||
|
|||||||
Reference in New Issue
Block a user