Handle errors#
All calendaring-jmap errors extend JMAPBaseError, and the JMAP-specific ones extend JMAPError, which adds an error_type string. See Design for why the hierarchy is shaped this way.
Catch specific error types#
from calendaring_jmap.error import (
JMAPAuthError,
JMAPCapabilityError,
JMAPError,
JMAPMethodError,
)
try:
event_id = client.create_event(calendar_id, ical)
except JMAPAuthError:
print("Authentication failed (401/403)")
except JMAPCapabilityError:
print("Server does not support urn:ietf:params:jmap:calendars")
except JMAPMethodError as e:
print(f"Server rejected the request: {e.error_type}, {e.reason}")
except JMAPError as e:
print(f"Protocol error: {e}")
See Errors for what each error class means and the full list of JMAP method error types.
Malformed iCalendar input#
create_event, send_invite, update_event, and the calendar/object convenience methods that call them (JMAPCalendar.add_event, JMAPCalendarObject.save) convert your iCalendar string to JSCalendar before sending it. If it’s missing a mandatory property (UID, DTSTART) or has a negative duration, they raise a plain ValueError, not a JMAPError subclass. This happens client-side, before any request reaches the server. Catch it if you’re constructing iCalendar strings by hand rather than passing through data a server already returned to you:
try:
event_id = client.create_event(calendar_id, ical)
except ValueError as e:
print(f"Malformed iCalendar: {e}")
except JMAPMethodError as e:
print(f"Server rejected the request: {e.error_type}, {e.reason}")