Callbacks & Events
onError
Fires when a recoverable error happens inside the widget.
onError is your hook to log, report, or react to failures the widget
handles gracefully.
Signature
onError?: (error: Error) => void;When it fires
- The API returns an error the widget can't recover from (e.g. invalid workspace, unauthorized).
- OTP verification fails after retries.
- The booking request itself fails.
- The initial client bootstrap fails (bad
apiKey).
The widget shows its own inline error UI regardless — onError is there
so you can send the error to your logging service (Sentry, Datadog, etc.)
or trigger a custom fallback.
Example — Sentry
import * as Sentry from "@sentry/browser";
MedosBooking.init({
apiKey: "mk_...",
onError: (err) => {
Sentry.captureException(err, { tags: { source: "medos-booking" } });
},
});Example — inline banner
MedosBooking.init({
apiKey: "mk_...",
onError: (err) => {
document.getElementById("booking-error").textContent = err.message;
},
});What error.message typically contains
"API key is required"— you forgot to passapiKey."Container with id "X" not found"— inline mode with a missing DOM node."MedosClient.init failed: ..."— the API rejected your key or the network call failed.- Backend error strings passed through from the API.
Don't rely on message strings for logic
Error message text can change between releases. If you need to branch on error type, ask the platform team about adding a stable error code — we're tracking that as a future improvement.