This commit is contained in:
swrup 2025-12-06 18:32:31 +01:00
parent 28d69de95a
commit dc78748f96
2 changed files with 62 additions and 8 deletions

View file

@ -66,16 +66,69 @@ module ErrorDetail = struct
type t = { type t = {
code: int; code: int;
hint: string option; hint: string option;
detail: string option;
parameter: string option;
path: string option;
offset: string option;
index: string option;
object_: string option;
currency: string option;
type_expected: string option;
type_actual: string option;
extra: Jsont.json option;
} }
let make code hint detail parameter path offset index object_ currency
type_expected type_actual extra =
{
code;
hint;
detail;
parameter;
path;
offset;
index;
object_;
currency;
type_expected;
type_actual;
extra;
}
let jsont = let jsont =
let make code hint = { code; hint } in let code v = v.code in
let enc_code v = v.code in let hint v = v.hint in
let enc_hint v = v.hint in let detail v = v.detail in
Jsont.Object.map ~kind:"ErrorDetail" make let parameter v = v.parameter in
|> Jsont.Object.mem "code" Jsont.int ~enc:enc_code let path v = v.path in
|> Jsont.Object.opt_mem "hint" Jsont.string ~enc:enc_hint let offset v = v.offset in
|> Jsont.Object.finish let index v = v.index in
let object_ v = v.object_ in
let currency v = v.currency in
let type_expected v = v.type_expected in
let type_actual v = v.type_actual in
let extra v = v.extra in
let open Jsont.Object in
map ~kind:"ErrorDetail" make
|> mem "code" Jsont.int ~enc:code
|> opt_mem "hint" Jsont.string ~enc:hint
|> opt_mem "detail" Jsont.string ~enc:detail
|> opt_mem "parameter" Jsont.string ~enc:parameter
|> opt_mem "path" Jsont.string ~enc:path
|> opt_mem "offset" Jsont.string ~enc:offset
|> opt_mem "index" Jsont.string ~enc:index
|> opt_mem "object" Jsont.string ~enc:object_
|> opt_mem "currency" Jsont.string ~enc:currency
|> opt_mem "type_expected" Jsont.string ~enc:type_expected
|> opt_mem "type_actual" Jsont.string ~enc:type_actual
|> opt_mem "extra" (Jsont.any ()) ~enc:extra
|> finish
let make ?hint ?detail ?parameter ?path ?offset ?index ?object_ ?currency
?type_expected ?type_actual ?extra code =
make code hint detail parameter path offset index object_ currency
type_expected type_actual extra
end end
module B32 = struct module B32 = struct

View file

@ -17,7 +17,8 @@ module Respond_with = struct
let error_detail ?hint _status = let error_detail ?hint _status =
let open Api in let open Api in
let code = -1 in let code = -1 in
let s = encode_exn ErrorDetail.jsont { code; hint } in let err = ErrorDetail.make ?hint code in
let s = encode_exn ErrorDetail.jsont err in
s s
end end