From 0325cd9167c650e88f27616be467d9de91c766aa Mon Sep 17 00:00:00 2001 From: Swrup Date: Wed, 1 Oct 2025 17:26:50 +0200 Subject: [PATCH] jsont error-detail --- src/dune | 2 +- src/mte.ml | 12 +++++------- src/types.ml | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 src/types.ml diff --git a/src/dune b/src/dune index d9a560ea..bd0df5e4 100644 --- a/src/dune +++ b/src/dune @@ -1,7 +1,7 @@ (executable (public_name mte) (name mte) - (modules assets assets_crunch headers mte config util) + (modules assets assets_crunch headers mte config util types) (libraries headers_lib syntax diff --git a/src/mte.ml b/src/mte.ml index cd406e4d..a9a60f15 100644 --- a/src/mte.ml +++ b/src/mte.ml @@ -13,13 +13,11 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . *) -(* TODO ??: GANA error codes - https://git.gnunet.org/gana.git/tree/gnu-taler-error-codes/registry.rec *) - -(* https://docs.taler.net/core/api-common.html#tsref-type-ErrorDetail *) -let error_detail ?hint status = - let _ = (hint, status) in - "{}" +let error_detail ?hint _status = + let open Types.ErrorDetail in + let code = -1 in + let s = to_string (make code hint) in + s module Respond_with = struct open Vif.Response diff --git a/src/types.ml b/src/types.ml new file mode 100644 index 00000000..7ba4d474 --- /dev/null +++ b/src/types.ml @@ -0,0 +1,19 @@ +(* https://docs.taler.net/core/api-common.html#tsref-type-ErrorDetail *) +module ErrorDetail = struct + (* TODO GANA error codes + https://git.gnunet.org/gana.git/tree/gnu-taler-error-codes/registry.rec *) + type t = { code: int; hint: string option } + + let make code hint = { code; hint } + let enc_code v = v.code + let enc_hint v = v.hint + + let jsont = + 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 to_string v = Jsont_bytesrw.encode_string jsont v |> Result.get_ok + let of_string v = Jsont_bytesrw.decode_string jsont v +end