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 <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2021-10-19 13:09:27 +02:00 committed by Dietmar Maurer
parent d6473f5359
commit 1d4448998a
1 changed files with 5 additions and 5 deletions

View File

@ -1,4 +1,5 @@
//! Helpers to format response data //! Helpers to format response data
use std::collections::HashMap;
use anyhow::{Error}; use anyhow::{Error};
use serde_json::{json, Value}; use serde_json::{json, Value};
@ -144,15 +145,14 @@ impl OutputFormatter for ExtJsFormatter {
fn format_error(&self, err: Error) -> Response<Body> { fn format_error(&self, err: Error) -> Response<Body> {
let message: String; let message: String;
let errors; let mut errors = HashMap::new();
if let Some(param_err) = err.downcast_ref::<ParameterError>() { if let Some(param_err) = err.downcast_ref::<ParameterError>() {
errors = param_err.errors().iter() for (name, err) in param_err.errors().iter() {
.map(|(name, err)| format!("parameter '{}': {}", name, err)) errors.insert(name, err.to_string());
.collect(); }
message = String::from("parameter verification errors"); message = String::from("parameter verification errors");
} else { } else {
errors = vec![];
message = err.to_string(); message = err.to_string();
} }