this repo has no description
1(** JMAP Error Types.
2 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-3.6> RFC 8620, Section 3.6 *)
3
4open Jmap_types
5
6(** Standard Method-level error types.
7 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-3.6.2> RFC 8620, Section 3.6.2 *)
8type method_error_type = [
9 | `ServerUnavailable
10 | `ServerFail
11 | `ServerPartialFail
12 | `UnknownMethod
13 | `InvalidArguments
14 | `InvalidResultReference
15 | `Forbidden
16 | `AccountNotFound
17 | `AccountNotSupportedByMethod
18 | `AccountReadOnly
19 | `RequestTooLarge
20 | `CannotCalculateChanges
21 | `StateMismatch
22 | `AnchorNotFound
23 | `UnsupportedSort
24 | `UnsupportedFilter
25 | `TooManyChanges
26 | `FromAccountNotFound
27 | `FromAccountNotSupportedByMethod
28 | `Other_method_error of string
29]
30
31(** Standard SetError types.
32 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-5.3> RFC 8620, Section 5.3 *)
33type set_error_type = [
34 | `Forbidden
35 | `OverQuota
36 | `TooLarge
37 | `RateLimit
38 | `NotFound
39 | `InvalidPatch
40 | `WillDestroy
41 | `InvalidProperties
42 | `Singleton
43 | `AlreadyExists (* From /copy *)
44 | `MailboxHasChild (* RFC 8621 *)
45 | `MailboxHasEmail (* RFC 8621 *)
46 | `BlobNotFound (* RFC 8621 *)
47 | `TooManyKeywords (* RFC 8621 *)
48 | `TooManyMailboxes (* RFC 8621 *)
49 | `InvalidEmail (* RFC 8621 *)
50 | `TooManyRecipients (* RFC 8621 *)
51 | `NoRecipients (* RFC 8621 *)
52 | `InvalidRecipients (* RFC 8621 *)
53 | `ForbiddenMailFrom (* RFC 8621 *)
54 | `ForbiddenFrom (* RFC 8621 *)
55 | `ForbiddenToSend (* RFC 8621 *)
56 | `CannotUnsend (* RFC 8621 *)
57 | `Other_set_error of string (* For future or custom errors *)
58]
59
60(** Primary error type that can represent all JMAP errors *)
61type error =
62 | Transport of string (** Network/HTTP-level error *)
63 | Parse of string (** JSON parsing error *)
64 | Protocol of string (** JMAP protocol error *)
65 | Problem of string (** Problem Details object error *)
66 | Method of method_error_type * string option (** Method error with optional description *)
67 | SetItem of id * set_error_type * string option (** Error for a specific item in a /set operation *)
68 | Auth of string (** Authentication error *)
69 | ServerError of string (** Server reported an error *)
70
71(** Standard Result type for JMAP operations *)
72type 'a result = ('a, error) Result.t
73
74(** Problem details object for HTTP-level errors.
75 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-3.6.1> RFC 8620, Section 3.6.1
76 @see <https://www.rfc-editor.org/rfc/rfc7807.html> RFC 7807 *)
77module Problem_details : sig
78 type t
79
80 val problem_type : t -> string
81 val status : t -> int option
82 val detail : t -> string option
83 val limit : t -> string option
84 val other_fields : t -> Yojson.Safe.t string_map
85
86 val v :
87 ?status:int ->
88 ?detail:string ->
89 ?limit:string ->
90 ?other_fields:Yojson.Safe.t string_map ->
91 string ->
92 t
93end
94
95(** Description for method errors. May contain additional details.
96 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-3.6.2> RFC 8620, Section 3.6.2 *)
97module Method_error_description : sig
98 type t
99
100 val description : t -> string option
101
102 val v : ?description:string -> unit -> t
103end
104
105(** Represents a method-level error response invocation part.
106 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-3.6.2> RFC 8620, Section 3.6.2 *)
107module Method_error : sig
108 type t
109
110 val type_ : t -> method_error_type
111 val description : t -> Method_error_description.t option
112
113 val v :
114 ?description:Method_error_description.t ->
115 method_error_type ->
116 t
117end
118
119(** SetError object.
120 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-5.3> RFC 8620, Section 5.3 *)
121module Set_error : sig
122 type t
123
124 val type_ : t -> set_error_type
125 val description : t -> string option
126 val properties : t -> string list option
127 val existing_id : t -> id option
128 val max_recipients : t -> uint option
129 val invalid_recipients : t -> string list option
130 val max_size : t -> uint option
131 val not_found_blob_ids : t -> id list option
132
133 val v :
134 ?description:string ->
135 ?properties:string list ->
136 ?existing_id:id ->
137 ?max_recipients:uint ->
138 ?invalid_recipients:string list ->
139 ?max_size:uint ->
140 ?not_found_blob_ids:id list ->
141 set_error_type ->
142 t
143end
144
145(** {2 Error Handling Functions} *)
146
147(** Create a transport error *)
148val transport_error : string -> error
149
150(** Create a parse error *)
151val parse_error : string -> error
152
153(** Create a protocol error *)
154val protocol_error : string -> error
155
156(** Create a problem details error *)
157val problem_error : Problem_details.t -> error
158
159(** Create a method error *)
160val method_error : ?description:string -> method_error_type -> error
161
162(** Create a SetItem error *)
163val set_item_error : id -> ?description:string -> set_error_type -> error
164
165(** Create an auth error *)
166val auth_error : string -> error
167
168(** Create a server error *)
169val server_error : string -> error
170
171(** Convert a Method_error.t to error *)
172val of_method_error : Method_error.t -> error
173
174(** Convert a Set_error.t to error for a specific ID *)
175val of_set_error : id -> Set_error.t -> error
176
177(** Get a human-readable description of an error *)
178val error_to_string : error -> string
179
180(** {2 Result Handling} *)
181
182(** Map an error with additional context *)
183val map_error : 'a result -> (error -> error) -> 'a result
184
185(** Add context to an error *)
186val with_context : 'a result -> string -> 'a result
187
188(** Convert an option to a result with an error for None *)
189val of_option : 'a option -> error -> 'a result