jspg error refactoring checkpoint
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
use std::collections::HashSet;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
pub mod context;
|
||||
pub mod error;
|
||||
@ -13,6 +13,7 @@ use crate::database::Database;
|
||||
use crate::validator::rules::util::is_integer;
|
||||
use serde_json::Value;
|
||||
use std::sync::Arc;
|
||||
use crate::drop::{Drop, Error, ErrorDetails};
|
||||
|
||||
pub struct Validator {
|
||||
pub db: Arc<Database>,
|
||||
@ -57,15 +58,15 @@ impl Validator {
|
||||
match ctx.validate_scoped() {
|
||||
Ok(result) => {
|
||||
if result.is_valid() {
|
||||
crate::drop::Drop::success()
|
||||
Drop::success()
|
||||
} else {
|
||||
let errors: Vec<crate::drop::Error> = result
|
||||
let errors: Vec<Error> = result
|
||||
.errors
|
||||
.into_iter()
|
||||
.map(|e| crate::drop::Error {
|
||||
.map(|e| Error {
|
||||
code: e.code,
|
||||
message: e.message,
|
||||
details: crate::drop::ErrorDetails {
|
||||
values: e.values,
|
||||
details: ErrorDetails {
|
||||
path: Some(e.path),
|
||||
cause: None,
|
||||
context: None,
|
||||
@ -73,13 +74,13 @@ impl Validator {
|
||||
},
|
||||
})
|
||||
.collect();
|
||||
crate::drop::Drop::with_errors(errors)
|
||||
Drop::with_errors(errors)
|
||||
}
|
||||
}
|
||||
Err(e) => crate::drop::Drop::with_errors(vec![crate::drop::Error {
|
||||
Err(e) => Drop::with_errors(vec![Error {
|
||||
code: e.code,
|
||||
message: e.message,
|
||||
details: crate::drop::ErrorDetails {
|
||||
values: e.values,
|
||||
details: ErrorDetails {
|
||||
path: Some(e.path),
|
||||
cause: None,
|
||||
context: None,
|
||||
@ -88,10 +89,12 @@ impl Validator {
|
||||
}]),
|
||||
}
|
||||
} else {
|
||||
crate::drop::Drop::with_errors(vec![crate::drop::Error {
|
||||
Drop::with_errors(vec![Error {
|
||||
code: "SCHEMA_NOT_FOUND".to_string(),
|
||||
message: format!("Schema {} not found", schema_id),
|
||||
details: crate::drop::ErrorDetails {
|
||||
values: Some(HashMap::from([
|
||||
("schema".to_string(), schema_id.to_string()),
|
||||
])),
|
||||
details: ErrorDetails {
|
||||
path: Some("/".to_string()),
|
||||
cause: None,
|
||||
context: None,
|
||||
|
||||
Reference in New Issue
Block a user