+5
-33
bin/fastmail_list.ml
+5
-33
bin/fastmail_list.ml
···
73
73
let* mailboxes_result = Jmap_mail.get_mailboxes conn ~account_id in
74
74
match mailboxes_result with
75
75
| Error err ->
76
-
Printf.printf "Error getting mailboxes: %s\n"
77
-
(match err with
78
-
| Jmap.Api.Connection_error msg -> "Connection error: " ^ msg
79
-
| Jmap.Api.HTTP_error (code, body) -> Printf.sprintf "HTTP error %d: %s" code body
80
-
| Jmap.Api.Parse_error msg -> "Parse error: " ^ msg
81
-
| Jmap.Api.Authentication_error -> "Authentication error");
76
+
Printf.printf "Error getting mailboxes: %s\n" (Api.string_of_error err);
82
77
Lwt.return_unit
83
78
84
79
| Ok mailboxes ->
···
102
97
103
98
match emails_result with
104
99
| Error err ->
105
-
Printf.printf "Error getting emails: %s\n"
106
-
(match err with
107
-
| Jmap.Api.Connection_error msg -> "Connection error: " ^ msg
108
-
| Jmap.Api.HTTP_error (code, body) -> Printf.sprintf "HTTP error %d: %s" code body
109
-
| Jmap.Api.Parse_error msg -> "Parse error: " ^ msg
110
-
| Jmap.Api.Authentication_error -> "Authentication error");
100
+
Printf.printf "Error getting emails: %s\n" (Api.string_of_error err);
111
101
Lwt.return_unit
112
102
113
103
| Ok emails ->
···
185
175
in
186
176
match result with
187
177
| Error err ->
188
-
(match err with
189
-
| Api.Connection_error msg ->
190
-
Printf.eprintf "Connection error: %s\n" msg
191
-
| Api.HTTP_error (code, body) ->
192
-
Printf.eprintf "HTTP error %d: %s\n" code body
193
-
| Api.Parse_error msg ->
194
-
Printf.eprintf "Parse error: %s\n" msg
195
-
| Api.Authentication_error ->
196
-
Printf.eprintf "Authentication error. Check your API token.\n");
178
+
Printf.eprintf "%s\n" (Api.string_of_error err);
197
179
Lwt.return 1
198
180
| Ok conn ->
199
181
(* Get the primary account ID *)
···
221
203
let* mailboxes_result = get_mailboxes conn ~account_id:primary_account_id in
222
204
match mailboxes_result with
223
205
| Error err ->
224
-
Printf.eprintf "Failed to get mailboxes: %s\n"
225
-
(match err with
226
-
| Api.Connection_error msg -> "Connection error: " ^ msg
227
-
| Api.HTTP_error (code, body) -> Printf.sprintf "HTTP error %d: %s" code body
228
-
| Api.Parse_error msg -> "Parse error: " ^ msg
229
-
| Api.Authentication_error -> "Authentication error");
206
+
Printf.eprintf "Failed to get mailboxes: %s\n" (Api.string_of_error err);
230
207
Lwt.return 1
231
208
| Ok mailboxes ->
232
209
(* If there's a mailbox list, just use the first one for this example *)
···
248
225
in
249
226
match emails_result with
250
227
| Error err ->
251
-
Printf.eprintf "Failed to get emails: %s\n"
252
-
(match err with
253
-
| Api.Connection_error msg -> "Connection error: " ^ msg
254
-
| Api.HTTP_error (code, body) -> Printf.sprintf "HTTP error %d: %s" code body
255
-
| Api.Parse_error msg -> "Parse error: " ^ msg
256
-
| Api.Authentication_error -> "Authentication error");
228
+
Printf.eprintf "Failed to get emails: %s\n" (Api.string_of_error err);
257
229
Lwt.return 1
258
230
| Ok emails ->
259
231
(* Apply filters based on command line arguments *)
+11
lib/jmap.ml
+11
lib/jmap.ml
···
442
442
443
443
(** Result type for API operations *)
444
444
type 'a result = ('a, error) Stdlib.result
445
+
446
+
(** Convert an error to a human-readable string *)
447
+
let string_of_error = function
448
+
| Connection_error msg -> "Connection error: " ^ msg
449
+
| HTTP_error (code, body) -> Printf.sprintf "HTTP error %d: %s" code body
450
+
| Parse_error msg -> "Parse error: " ^ msg
451
+
| Authentication_error -> "Authentication error"
452
+
453
+
(** Pretty-print an error to a formatter *)
454
+
let pp_error ppf err =
455
+
Format.fprintf ppf "%s" (string_of_error err)
445
456
446
457
(** Configuration for a JMAP API client *)
447
458
type config = {
+12
lib/jmap.mli
+12
lib/jmap.mli
···
579
579
(** Result type for API operations *)
580
580
type 'a result = ('a, error) Stdlib.result
581
581
582
+
(** Convert an error to a human-readable string
583
+
@param err The error to convert
584
+
@return A string representation of the error
585
+
*)
586
+
val string_of_error : error -> string
587
+
588
+
(** Pretty-print an error to a formatter
589
+
@param ppf The formatter to print to
590
+
@param err The error to print
591
+
*)
592
+
val pp_error : Format.formatter -> error -> unit
593
+
582
594
(** Configuration for a JMAP API client as defined in RFC8620 Section 3.1
583
595
@see <https://datatracker.ietf.org/doc/html/rfc8620#section-3.1>
584
596
*)