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,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { apiFetch } from '$lib/utils/api';
|
||||
import { toast } from 'svelte-sonner';
|
||||
import { extractErrorMessage } from '$lib/utils/toast-safe';
|
||||
import { SvelteDate, SvelteSet, SvelteURLSearchParams } from 'svelte/reactivity';
|
||||
import { CalendarDate, getLocalTimeZone, type DateValue } from '@internationalized/date';
|
||||
import { isValidUKPhone, toE164UK } from '$lib/utils/phone';
|
||||
@@ -718,7 +719,7 @@
|
||||
return false;
|
||||
} else {
|
||||
const errorText = await response.text();
|
||||
toast.error(`Failed to reserve slot: ${errorText}`);
|
||||
toast.error(`Failed to reserve slot: ${extractErrorMessage(errorText)}`);
|
||||
return false;
|
||||
}
|
||||
} catch {
|
||||
@@ -855,7 +856,7 @@
|
||||
toast.success('Custom service created and added');
|
||||
} else {
|
||||
const err = await response.text();
|
||||
toast.error(`Failed: ${err}`);
|
||||
toast.error(`Failed: ${extractErrorMessage(err)}`);
|
||||
}
|
||||
} catch {
|
||||
toast.error('Network error');
|
||||
@@ -1014,7 +1015,7 @@
|
||||
onBookingCreated?.();
|
||||
} else {
|
||||
const errorText = await res.text();
|
||||
toast.error(`Failed to create booking: ${errorText}`);
|
||||
toast.error(`Failed to create booking: ${extractErrorMessage(errorText)}`);
|
||||
}
|
||||
} catch {
|
||||
toast.error('An error occurred while creating booking');
|
||||
|
||||
Reference in New Issue
Block a user