Implement health check service and global exception handling

This commit is contained in:
Nils-Johan Gynther
2026-04-10 18:14:48 +02:00
parent 650a1bb55c
commit 2efb5b5627
10 changed files with 327 additions and 36 deletions
@@ -3,6 +3,7 @@
import { useState, useEffect } from 'react';
import { useRouter } from 'next/navigation';
import { fetchJson } from '../../../lib/api';
import { parseErrorResponse } from '../../../lib/error-handler';
import type { Product } from '../../../features/inventory/types';
export default function CreateRecipePage() {
@@ -64,12 +65,14 @@ export default function CreateRecipePage() {
});
if (!response.ok) {
throw new Error('Kunde inte spara receptet');
const errorMessage = await parseErrorResponse(response);
throw new Error(errorMessage);
}
router.push('/recipes');
} catch (err) {
setError((err as Error).message);
const message = err instanceof Error ? err.message : 'Ett okänt fel inträffade. Försök igen.';
setError(message);
} finally {
setIsLoading(false);
}