Skip to content

Commit

Permalink
Merge pull request #28 from kije/main
Browse files Browse the repository at this point in the history
Update to support rocket =0.5.0-rc.4
  • Loading branch information
somehowchris authored Nov 7, 2023
2 parents 42c7e55 + 1173eb2 commit df61097
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ description = "Rocket Guards to support validation using validator"
path = "src/lib.rs"

[dependencies]
rocket = { version = "0.5.0-rc.2", default-features = false, features = [
rocket = { version = "0.5.0-rc.4", default-features = false, features = [
"json",
] }
validator = { version = "0.16.0", features = ["derive"] }
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,13 @@ impl<'r, D: Validate + rocket::serde::Deserialize<'r>> FromData<'r> for Validate
let data_outcome = <Json<D> as FromData<'r>>::from_data(req, data).await;

match data_outcome {
Outcome::Failure((status, err)) => Outcome::Failure((status, Err(err))),
Outcome::Error((status, err)) => Outcome::Error((status, Err(err))),
Outcome::Forward(err) => Outcome::Forward(err),
Outcome::Success(data) => match data.validate() {
Ok(_) => Outcome::Success(Validated(data)),
Err(err) => {
req.local_cache(|| CachedValidationErrors(Some(err.to_owned())));
Outcome::Failure((Status::BadRequest, Ok(err)))
Outcome::Error((Status::BadRequest, Ok(err)))
}
},
}
Expand All @@ -207,13 +207,13 @@ impl<'r, D: Validate + FromRequest<'r>> FromRequest<'r> for Validated<D> {
let data_outcome = D::from_request(req).await;

match data_outcome {
Outcome::Failure((status, err)) => Outcome::Failure((status, Err(err))),
Outcome::Error((status, err)) => Outcome::Error((status, Err(err))),
Outcome::Forward(err) => Outcome::Forward(err),
Outcome::Success(data) => match data.validate() {
Ok(_) => Outcome::Success(Validated(data)),
Err(err) => {
req.local_cache(|| CachedValidationErrors(Some(err.to_owned())));
Outcome::Failure((Status::BadRequest, Ok(err)))
Outcome::Error((Status::BadRequest, Ok(err)))
}
},
}
Expand Down
6 changes: 3 additions & 3 deletions tests/test_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn invalid_short_name() {

let response: LocalResponse = req.dispatch();

assert_eq!(response.status(), Status::NotFound);
assert_eq!(response.status(), Status::UnprocessableEntity);
assert_eq!(response.content_type(), Some(ContentType::HTML));
}

Expand All @@ -80,7 +80,7 @@ pub fn invalid_min_age() {

let response: LocalResponse = req.dispatch();

assert_eq!(response.status(), Status::NotFound);
assert_eq!(response.status(), Status::UnprocessableEntity);
assert_eq!(response.content_type(), Some(ContentType::HTML));
}

Expand All @@ -92,6 +92,6 @@ pub fn invalid_max_age() {

let response: LocalResponse = req.dispatch();

assert_eq!(response.status(), Status::NotFound);
assert_eq!(response.status(), Status::UnprocessableEntity);
assert_eq!(response.content_type(), Some(ContentType::HTML));
}

0 comments on commit df61097

Please sign in to comment.