From b87aa76b643b627a0f60f9442bbdc23884238034 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Tue, 19 Oct 2021 13:09:27 +0200 Subject: [PATCH] rest-server: use hashmap for parameter errors 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 --- 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 { let message: String; - let errors; + let mut errors = HashMap::new(); if let Some(param_err) = err.downcast_ref::() { - 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(); }