import { relayServerFailure } from '../../../../../utils/fetchFailureMessage'; import { asDenial } from '../../../../../utils/booking/appointmentGuardOutcome'; import { BookingStorageUnavailableError } from '../../../../../utils/booking/bookingOperation'; const FALLBACK = "We couldn't book this appointment. Please try again."; // What a patient reads when a booking failed for a reason the form did not expect. Only an answer from // the server can carry a sentence written for people; anything else says the booking did not go through. export const bookingFailure = (error: unknown): string => { // Nothing was sent: the device could not keep the booking, and the sentence says what to change. if (error instanceof BookingStorageUnavailableError) return error.message; const answered = typeof (error as { status?: unknown } | null)?.status === 'number'; return answered ? relayServerFailure(error, FALLBACK) : FALLBACK; }; // A 403 is the practice refusing what was chosen, not a failure to retry: the server's own sentence, // as a denial, for the patient to read where they choose again. Undefined for anything else. export const bookingRefusal = (error: unknown): string | undefined => { if ((error as { status?: unknown } | null)?.status !== 403) return undefined; return asDenial(relayServerFailure(error, FALLBACK)); };