My agentic slop goes here. Not intended for anyone else!

more

Changed files
+92
stack
zulip
+62
stack/zulip/lib/zulip/lib/zulip_types.ml
···
+
(** Core types for Zulip API *)
+
+
(** JSON type used throughout the API *)
+
type json = [`Null | `Bool of bool | `Float of float | `String of string | `A of json list | `O of (string * json) list]
+
+
(** Error codes returned by Zulip API *)
+
type error_code =
+
| Invalid_api_key
+
| Request_variable_missing
+
| Bad_request
+
| User_deactivated
+
| Realm_deactivated
+
| Rate_limit_hit
+
| Other of string
+
+
(** Zulip-specific error type *)
+
type zerror = {
+
code : error_code;
+
message : string;
+
extra : (string * json) list;
+
}
+
+
let error_code_to_string = function
+
| Invalid_api_key -> "INVALID_API_KEY"
+
| Request_variable_missing -> "REQUEST_VARIABLE_MISSING"
+
| Bad_request -> "BAD_REQUEST"
+
| User_deactivated -> "USER_DEACTIVATED"
+
| Realm_deactivated -> "REALM_DEACTIVATED"
+
| Rate_limit_hit -> "RATE_LIMIT_HIT"
+
| Other s -> s
+
+
let error_code_of_string s = match s with
+
| "INVALID_API_KEY" -> Invalid_api_key
+
| "REQUEST_VARIABLE_MISSING" -> Request_variable_missing
+
| "BAD_REQUEST" -> Bad_request
+
| "USER_DEACTIVATED" -> User_deactivated
+
| "REALM_DEACTIVATED" -> Realm_deactivated
+
| "RATE_LIMIT_HIT" -> Rate_limit_hit
+
| s -> Other s
+
+
let create_error ~code ~msg ?(extra = []) () = { code; message = msg; extra }
+
let error_code t = t.code
+
let error_message t = t.message
+
let error_extra t = t.extra
+
let pp_error fmt t = Format.fprintf fmt "Error(%s): %s"
+
(error_code_to_string t.code) t.message
+
+
let error_of_json json =
+
match json with
+
| `O fields ->
+
(try
+
let code_str = match List.assoc "code" fields with
+
| `String s -> s
+
| _ -> "OTHER" in
+
let msg = match List.assoc "msg" fields with
+
| `String s -> s
+
| _ -> "Unknown error" in
+
let code = error_code_of_string code_str in
+
let extra = List.filter (fun (k, _) -> k <> "code" && k <> "msg" && k <> "result") fields in
+
Some (create_error ~code ~msg ~extra ())
+
with Not_found -> None)
+
| _ -> None
+30
stack/zulip/lib/zulip/lib/zulip_types.mli
···
+
(** Core types for Zulip API *)
+
+
(** JSON type used throughout the API *)
+
type json = [`Null | `Bool of bool | `Float of float | `String of string | `A of json list | `O of (string * json) list]
+
+
(** Error codes returned by Zulip API *)
+
type error_code =
+
| Invalid_api_key
+
| Request_variable_missing
+
| Bad_request
+
| User_deactivated
+
| Realm_deactivated
+
| Rate_limit_hit
+
| Other of string
+
+
(** Zulip-specific error type *)
+
type zerror = {
+
code : error_code;
+
message : string;
+
extra : (string * json) list;
+
}
+
+
val error_code_to_string : error_code -> string
+
val error_code_of_string : string -> error_code
+
val create_error : code:error_code -> msg:string -> ?extra:(string * json) list -> unit -> zerror
+
val error_code : zerror -> error_code
+
val error_message : zerror -> string
+
val error_extra : zerror -> (string * json) list
+
val pp_error : Format.formatter -> zerror -> unit
+
val error_of_json : json -> zerror option