From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup] rest-server: use hashmap for parameter errors
Date: Tue, 19 Oct 2021 13:09:27 +0200 [thread overview]
Message-ID: <20211019110927.3708603-1-d.csapak@proxmox.com> (raw)
our ui expects a map here with 'field: "error"'. This way it can mark
the relevant field as invalid and correctly shows the complete error
message
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
proxmox-rest-server/src/formatter.rs | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/proxmox-rest-server/src/formatter.rs b/proxmox-rest-server/src/formatter.rs
index 6d050997..cb5774d5 100644
--- a/proxmox-rest-server/src/formatter.rs
+++ b/proxmox-rest-server/src/formatter.rs
@@ -1,4 +1,5 @@
//! Helpers to format response data
+use std::collections::HashMap;
use anyhow::{Error};
use serde_json::{json, Value};
@@ -144,15 +145,14 @@ impl OutputFormatter for ExtJsFormatter {
fn format_error(&self, err: Error) -> Response<Body> {
let message: String;
- let errors;
+ let mut errors = HashMap::new();
if let Some(param_err) = err.downcast_ref::<ParameterError>() {
- errors = param_err.errors().iter()
- .map(|(name, err)| format!("parameter '{}': {}", name, err))
- .collect();
+ for (name, err) in param_err.errors().iter() {
+ errors.insert(name, err.to_string());
+ }
message = String::from("parameter verification errors");
} else {
- errors = vec![];
message = err.to_string();
}
--
2.30.2
next reply other threads:[~2021-10-19 11:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-19 11:09 Dominik Csapak [this message]
2021-10-21 4:32 ` [pbs-devel] applied: " Dietmar Maurer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211019110927.3708603-1-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox