From dc78748f96417a52e85f7bbfd5d89d6b87fc7dd5 Mon Sep 17 00:00:00 2001 From: swrup Date: Sat, 6 Dec 2025 18:32:31 +0100 Subject: [PATCH] --- src/api.ml | 67 +++++++++++++++++++++++++++++++++++++++++++++------ src/static.ml | 3 ++- 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/src/api.ml b/src/api.ml index c4c7877f..579da672 100644 --- a/src/api.ml +++ b/src/api.ml @@ -66,16 +66,69 @@ module ErrorDetail = struct type t = { code: int; 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 make code hint = { code; hint } in - let enc_code v = v.code in - let enc_hint v = v.hint in - Jsont.Object.map ~kind:"ErrorDetail" make - |> Jsont.Object.mem "code" Jsont.int ~enc:enc_code - |> Jsont.Object.opt_mem "hint" Jsont.string ~enc:enc_hint - |> Jsont.Object.finish + let code v = v.code in + let hint v = v.hint in + let detail v = v.detail in + let parameter v = v.parameter in + let path v = v.path in + let offset v = v.offset in + 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 module B32 = struct diff --git a/src/static.ml b/src/static.ml index a69d2dc0..57b24dcd 100644 --- a/src/static.ml +++ b/src/static.ml @@ -17,7 +17,8 @@ module Respond_with = struct let error_detail ?hint _status = let open Api 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 end