View Issue Details

IDProjectCategoryView StatusLast Update
0012177Talerexchangepublic2026-11-18 14:42
Reporterbot-cg [agent]  
PrioritynormalSeverityminor 
Status new 
Summary0012177: taler-api: allow extra details in error responses
DescriptionErrorDetail has an extra field, but ApiError always sent it as null, so per-field validation problems had no place in the response.

Files: common/taler-api/src/error.rs (paths in the taler-rust tree). The patch is attached; it is number 2 of the series in the parent issue, against taler-rust 2c678873, and applies on top of the patches before it.
TagsNo tags attached.
Attached Files
0002-api-allow-extra-details-in-error-responses.patch (3,060 bytes)   
From f0675b35328085ede7b3a31b13e5bf5f1f5b0c67 Mon Sep 17 00:00:00 2001
From: Christian Grothoff <christian@grothoff.org>
Date: Tue, 29 Sep 2026 13:48:51 +0200
Subject: [PATCH 2/9] api: allow extra details in error responses

ErrorDetail has an extra field, but ApiError always sent it as null, so per-field validation problems had no place in the response.
---
 common/taler-api/src/error.rs | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/common/taler-api/src/error.rs b/common/taler-api/src/error.rs
index a6e5897..f6494ca 100644
--- a/common/taler-api/src/error.rs
+++ b/common/taler-api/src/error.rs
@@ -135,6 +135,7 @@ pub struct ApiError {
     status: Option<StatusCode>,
     path: Option<Box<str>>,
     headers: Option<Box<HeaderMap>>,
+    extra: Option<Box<serde_json::value::RawValue>>,
 }
 
 impl Display for ApiError {
@@ -156,6 +157,7 @@ impl ApiError {
             status: None,
             path: None,
             headers: None,
+            extra: None,
         }
     }
 
@@ -187,6 +189,18 @@ impl ApiError {
         }
     }
 
+    /// Set the `extra` field of the error response, for details that the
+    /// other fields cannot express (e.g. a list of validation problems).
+    pub fn with_extra(self, extra: &impl Serialize) -> Self {
+        match serde_json::value::to_raw_value(extra) {
+            Ok(raw) => Self {
+                extra: Some(raw),
+                ..self
+            },
+            Err(e) => self.with_log(format!("unserializable error details: {e}")),
+        }
+    }
+
     pub fn with_header(mut self, key: impl IntoHeaderName, value: HeaderValue) -> Self {
         let headers = self.headers.get_or_insert_default();
         headers.append(key, value);
@@ -215,6 +229,7 @@ impl From<sqlx::Error> for ApiError {
             log: Some(format!("{value}").into_boxed_str()),
             path: None,
             headers: None,
+            extra: None,
         }
     }
 }
@@ -285,6 +300,7 @@ impl IntoResponse for ApiError {
             status,
             path,
             headers,
+            extra,
         } = self;
         let status_code = status
             .unwrap_or_else(|| StatusCode::from_u16(code.status()).expect("Invalid status code"));
@@ -304,7 +320,7 @@ impl IntoResponse for ApiError {
                 currency: None,
                 type_expected: None,
                 type_actual: None,
-                extra: None,
+                extra,
             }),
         )
             .into_response();
@@ -381,4 +397,12 @@ mod tests {
         // Same shape as ErrorDetail: absent fields are null.
         assert!(json["detail"].is_null() && json.get("detail").is_some());
     }
+
+    #[tokio::test]
+    async fn extra_details() {
+        let err = failure_code(ErrorCode::GENERIC_JSON_INVALID)
+            .with_extra(&serde_json::json!({"errors": {"name": ["required"]}}));
+        let (_, json) = body(err).await;
+        assert_eq!(json["extra"]["errors"]["name"][0], "required");
+    }
 }
-- 
2.47.3

Required notifications

Address or linkRemarkAdded byNotifiedActions

Relationships

child of 0012175 new taler-api: nine patches that Beekeeper carries on its vendored copy (patch series attached) 

Activities

bot-cg [agent]

2026-11-18 14:42

updater   ~0030576

Correction: this issue was filed in the category "exchange" by mistake. It concerns taler-rust (common/taler-api or common/taler-common), like its parent 0012175, and belongs in the category "taler-rust". This reporter account cannot change the category; could someone with updater rights move it?

Issue History

Date ModifiedUsernameFieldChange
2026-11-18 14:41bot-cgNew Issue
2026-11-18 14:41bot-cgRelationship addedchild of 0012175
2026-11-18 14:41bot-cgImplementer => oec
2026-11-18 14:41bot-cgReviewer => Christian Grothoff
2026-11-18 14:41bot-cgRelease signed by => Christian Grothoff
2026-11-18 14:41bot-cgDeployed by => Christian Grothoff
2026-11-18 14:41bot-cgVerifier => oec
2026-11-18 14:41bot-cgCommunicator => CM_7
2026-11-18 14:42bot-cgFile Added: 0002-api-allow-extra-details-in-error-responses.patch
2026-11-18 14:42bot-cgNote Added: 0030576