|
| 1 | +"""JMAP error types as per RFC 8620.""" |
| 2 | + |
| 3 | + |
| 4 | +class JMAPError(Exception): |
| 5 | + """Base JMAP error.""" |
| 6 | + |
| 7 | + error_type: str = "serverFail" |
| 8 | + |
| 9 | + def __init__(self, description: str = ""): |
| 10 | + self.description = description |
| 11 | + super().__init__(description) |
| 12 | + |
| 13 | + def to_response(self, call_id: str) -> list: |
| 14 | + """Convert to JMAP error response tuple.""" |
| 15 | + return [ |
| 16 | + "error", |
| 17 | + {"type": self.error_type, "description": self.description}, |
| 18 | + call_id, |
| 19 | + ] |
| 20 | + |
| 21 | + |
| 22 | +class UnknownCapabilityError(JMAPError): |
| 23 | + """The request used a capability not advertised in the session.""" |
| 24 | + |
| 25 | + error_type = "unknownCapability" |
| 26 | + |
| 27 | + |
| 28 | +class UnknownMethodError(JMAPError): |
| 29 | + """The method name is not recognized.""" |
| 30 | + |
| 31 | + error_type = "unknownMethod" |
| 32 | + |
| 33 | + |
| 34 | +class InvalidArgumentsError(JMAPError): |
| 35 | + """One or more arguments are of the wrong type or invalid.""" |
| 36 | + |
| 37 | + error_type = "invalidArguments" |
| 38 | + |
| 39 | + |
| 40 | +class InvalidResultReferenceError(JMAPError): |
| 41 | + """A result reference could not be resolved.""" |
| 42 | + |
| 43 | + error_type = "invalidResultReference" |
| 44 | + |
| 45 | + |
| 46 | +class AccountNotFoundError(JMAPError): |
| 47 | + """The accountId does not correspond to a valid account.""" |
| 48 | + |
| 49 | + error_type = "accountNotFound" |
| 50 | + |
| 51 | + |
| 52 | +class ForbiddenError(JMAPError): |
| 53 | + """The action is forbidden for the authenticated user.""" |
| 54 | + |
| 55 | + error_type = "forbidden" |
| 56 | + |
| 57 | + |
| 58 | +class ServerFailError(JMAPError): |
| 59 | + """An unexpected server error occurred.""" |
| 60 | + |
| 61 | + error_type = "serverFail" |
0 commit comments