fix: sanitize API error text display and add time_blockers tests
Add extractErrorMessage helper for JSON error body parsing and apply sanitizeText across all toast displays. Add time_blockers test coverage for new holiday placeholder cleanup and overlapping scenarios.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { toast } from 'svelte-sonner';
|
||||
import { extractErrorMessage } from '$lib/utils/toast-safe';
|
||||
import { apiFetch } from '$lib/utils/api';
|
||||
import { range } from '$lib/utils/format';
|
||||
|
||||
@@ -192,7 +193,7 @@
|
||||
await fetchServices();
|
||||
} else {
|
||||
const errorText = await response.text();
|
||||
toast.error(`Failed to update service: ${errorText}`);
|
||||
toast.error(`Failed to update service: ${extractErrorMessage(errorText)}`);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error toggling service:', err);
|
||||
@@ -219,7 +220,7 @@
|
||||
await fetchServices();
|
||||
} else {
|
||||
const errorText = await response.text();
|
||||
toast.error(`Failed to delete service: ${errorText}`);
|
||||
toast.error(`Failed to delete service: ${extractErrorMessage(errorText)}`);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error deleting service:', err);
|
||||
@@ -275,10 +276,10 @@
|
||||
toast.error('A service with this name already exists', { id: loadingToast });
|
||||
} else if (response.status === 400) {
|
||||
const errorText = await response.text();
|
||||
toast.error(`Validation error: ${errorText}`, { id: loadingToast });
|
||||
toast.error(`Validation error: ${extractErrorMessage(errorText)}`, { id: loadingToast });
|
||||
} else {
|
||||
const errorText = await response.text();
|
||||
toast.error(`Failed to create service: ${errorText}`, { id: loadingToast });
|
||||
toast.error(`Failed to create service: ${extractErrorMessage(errorText)}`, { id: loadingToast });
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error creating service:', err);
|
||||
|
||||
Reference in New Issue
Block a user