ExtJsFormatter: use ParameterError to correctly compute 'errors'
By default, 'errors' is now empty. Depend on proxmox 0.13.5.
This commit is contained in:
@ -25,7 +25,7 @@ tokio-openssl = "0.6.1"
|
||||
tower-service = "0.3.0"
|
||||
url = "2.1"
|
||||
|
||||
proxmox = { version = "0.13.4", features = [ "router"] }
|
||||
proxmox = { version = "0.13.5", features = [ "router"] }
|
||||
|
||||
# fixme: remove this dependency (pbs_tools::broadcast_future)
|
||||
pbs-tools = { path = "../pbs-tools" }
|
||||
|
@ -6,7 +6,7 @@ use serde_json::{json, Value};
|
||||
use hyper::{Body, Response, StatusCode};
|
||||
use hyper::header;
|
||||
|
||||
use proxmox::api::{HttpError, RpcEnvironment};
|
||||
use proxmox::api::{HttpError, schema::ParameterError, RpcEnvironment};
|
||||
|
||||
/// Extension to set error message for server side logging
|
||||
pub(crate) struct ErrorMessageExtension(pub String);
|
||||
@ -61,6 +61,12 @@ struct JsonFormatter();
|
||||
|
||||
/// Format data as ``application/json``
|
||||
///
|
||||
/// The returned json object contains the following properties:
|
||||
///
|
||||
/// * ``data``: The result data (on success)
|
||||
///
|
||||
/// Any result attributes set on ``rpcenv`` are also added to the object.
|
||||
///
|
||||
/// Errors generates a BAD_REQUEST containing the error
|
||||
/// message as string.
|
||||
pub static JSON_FORMATTER: &'static dyn OutputFormatter = &JsonFormatter();
|
||||
@ -136,10 +142,18 @@ impl OutputFormatter for ExtJsFormatter {
|
||||
|
||||
fn format_error(&self, err: Error) -> Response<Body> {
|
||||
|
||||
let mut errors = vec![];
|
||||
let message: String;
|
||||
let errors;
|
||||
|
||||
let message = err.to_string();
|
||||
errors.push(&message);
|
||||
if let Some(param_err) = err.downcast_ref::<ParameterError>() {
|
||||
errors = param_err.errors().iter()
|
||||
.map(|(name, err)| format!("parameter '{}': {}", name, err))
|
||||
.collect();
|
||||
message = String::from("parameter verification errors");
|
||||
} else {
|
||||
errors = vec![];
|
||||
message = err.to_string();
|
||||
}
|
||||
|
||||
let result = json!({
|
||||
"message": message,
|
||||
|
Reference in New Issue
Block a user