this repo has no description
at main 202 lines 6.1 kB view raw
1(*--------------------------------------------------------------------------- 2 Copyright (c) 2025 Anil Madhavapeddy. All rights reserved. 3 SPDX-License-Identifier: ISC 4 ---------------------------------------------------------------------------*) 5 6module Request_error = struct 7 type urn = [ 8 | `Unknown_capability 9 | `Not_json 10 | `Not_request 11 | `Limit 12 | `Other of string 13 ] 14 15 let urn_to_string = function 16 | `Unknown_capability -> "urn:ietf:params:jmap:error:unknownCapability" 17 | `Not_json -> "urn:ietf:params:jmap:error:notJSON" 18 | `Not_request -> "urn:ietf:params:jmap:error:notRequest" 19 | `Limit -> "urn:ietf:params:jmap:error:limit" 20 | `Other s -> s 21 22 let urn_of_string = function 23 | "urn:ietf:params:jmap:error:unknownCapability" -> `Unknown_capability 24 | "urn:ietf:params:jmap:error:notJSON" -> `Not_json 25 | "urn:ietf:params:jmap:error:notRequest" -> `Not_request 26 | "urn:ietf:params:jmap:error:limit" -> `Limit 27 | s -> `Other s 28 29 let urn_jsont = 30 let kind = "Request error URN" in 31 Jsont.map ~kind 32 ~dec:(fun s -> urn_of_string s) 33 ~enc:urn_to_string 34 Jsont.string 35 36 type t = { 37 type_ : urn; 38 status : int; 39 title : string option; 40 detail : string option; 41 limit : string option; 42 } 43 44 let make type_ status title detail limit = 45 { type_; status; title; detail; limit } 46 47 let type_ t = t.type_ 48 let status t = t.status 49 let title t = t.title 50 let detail t = t.detail 51 let limit t = t.limit 52 53 let jsont = 54 let kind = "Request error" in 55 Jsont.Object.map ~kind make 56 |> Jsont.Object.mem "type" urn_jsont ~enc:type_ 57 |> Jsont.Object.mem "status" Jsont.int ~enc:status 58 |> Jsont.Object.opt_mem "title" Jsont.string ~enc:title 59 |> Jsont.Object.opt_mem "detail" Jsont.string ~enc:detail 60 |> Jsont.Object.opt_mem "limit" Jsont.string ~enc:limit 61 |> Jsont.Object.finish 62end 63 64type method_error_type = [ 65 | `Server_unavailable 66 | `Server_fail 67 | `Server_partial_fail 68 | `Unknown_method 69 | `Invalid_arguments 70 | `Invalid_result_reference 71 | `Forbidden 72 | `Account_not_found 73 | `Account_not_supported_by_method 74 | `Account_read_only 75 | `Other of string 76] 77 78let method_error_type_to_string = function 79 | `Server_unavailable -> "serverUnavailable" 80 | `Server_fail -> "serverFail" 81 | `Server_partial_fail -> "serverPartialFail" 82 | `Unknown_method -> "unknownMethod" 83 | `Invalid_arguments -> "invalidArguments" 84 | `Invalid_result_reference -> "invalidResultReference" 85 | `Forbidden -> "forbidden" 86 | `Account_not_found -> "accountNotFound" 87 | `Account_not_supported_by_method -> "accountNotSupportedByMethod" 88 | `Account_read_only -> "accountReadOnly" 89 | `Other s -> s 90 91let method_error_type_of_string = function 92 | "serverUnavailable" -> `Server_unavailable 93 | "serverFail" -> `Server_fail 94 | "serverPartialFail" -> `Server_partial_fail 95 | "unknownMethod" -> `Unknown_method 96 | "invalidArguments" -> `Invalid_arguments 97 | "invalidResultReference" -> `Invalid_result_reference 98 | "forbidden" -> `Forbidden 99 | "accountNotFound" -> `Account_not_found 100 | "accountNotSupportedByMethod" -> `Account_not_supported_by_method 101 | "accountReadOnly" -> `Account_read_only 102 | s -> `Other s 103 104let method_error_type_jsont = 105 let kind = "Method error type" in 106 Jsont.map ~kind 107 ~dec:(fun s -> method_error_type_of_string s) 108 ~enc:method_error_type_to_string 109 Jsont.string 110 111type method_error = { 112 type_ : method_error_type; 113 description : string option; 114} 115 116let method_error_make type_ description = { type_; description } 117let method_error_type_ t = t.type_ 118let method_error_description t = t.description 119 120let method_error_jsont = 121 let kind = "Method error" in 122 Jsont.Object.map ~kind method_error_make 123 |> Jsont.Object.mem "type" method_error_type_jsont ~enc:method_error_type_ 124 |> Jsont.Object.opt_mem "description" Jsont.string ~enc:method_error_description 125 |> Jsont.Object.finish 126 127type set_error_type = [ 128 | `Forbidden 129 | `Over_quota 130 | `Too_large 131 | `Rate_limit 132 | `Not_found 133 | `Invalid_patch 134 | `Will_destroy 135 | `Invalid_properties 136 | `Singleton 137 | `Forbidden_mail_from 138 | `Forbidden_from 139 | `Forbidden_to_send 140 | `Other of string 141] 142 143let set_error_type_to_string = function 144 | `Forbidden -> "forbidden" 145 | `Over_quota -> "overQuota" 146 | `Too_large -> "tooLarge" 147 | `Rate_limit -> "rateLimit" 148 | `Not_found -> "notFound" 149 | `Invalid_patch -> "invalidPatch" 150 | `Will_destroy -> "willDestroy" 151 | `Invalid_properties -> "invalidProperties" 152 | `Singleton -> "singleton" 153 | `Forbidden_mail_from -> "forbiddenMailFrom" 154 | `Forbidden_from -> "forbiddenFrom" 155 | `Forbidden_to_send -> "forbiddenToSend" 156 | `Other s -> s 157 158let set_error_type_of_string = function 159 | "forbidden" -> `Forbidden 160 | "overQuota" -> `Over_quota 161 | "tooLarge" -> `Too_large 162 | "rateLimit" -> `Rate_limit 163 | "notFound" -> `Not_found 164 | "invalidPatch" -> `Invalid_patch 165 | "willDestroy" -> `Will_destroy 166 | "invalidProperties" -> `Invalid_properties 167 | "singleton" -> `Singleton 168 | "forbiddenMailFrom" -> `Forbidden_mail_from 169 | "forbiddenFrom" -> `Forbidden_from 170 | "forbiddenToSend" -> `Forbidden_to_send 171 | s -> `Other s 172 173let set_error_type_jsont = 174 let kind = "SetError type" in 175 Jsont.map ~kind 176 ~dec:(fun s -> set_error_type_of_string s) 177 ~enc:set_error_type_to_string 178 Jsont.string 179 180type set_error = { 181 type_ : set_error_type; 182 description : string option; 183 properties : string list option; 184} 185 186let set_error ?description ?properties type_ = 187 { type_; description; properties } 188 189let set_error_make type_ description properties = 190 { type_; description; properties } 191 192let set_error_type_ t = t.type_ 193let set_error_description t = t.description 194let set_error_properties t = t.properties 195 196let set_error_jsont = 197 let kind = "SetError" in 198 Jsont.Object.map ~kind set_error_make 199 |> Jsont.Object.mem "type" set_error_type_jsont ~enc:set_error_type_ 200 |> Jsont.Object.opt_mem "description" Jsont.string ~enc:set_error_description 201 |> Jsont.Object.opt_mem "properties" (Jsont.list Jsont.string) ~enc:set_error_properties 202 |> Jsont.Object.finish