Created
May 20, 2018 16:43
-
-
Save lankydan/c5e8a203cad89fad50d686c072a7a1b8 to your computer and use it in GitHub Desktop.
Building a REST API with Rust, Rocket and Diesel - handler all function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[get("/")] | |
fn all(connection: DbConn) -> Result<Json<Vec<Person>>, Failure> { | |
people::repository::all(&connection) | |
.map(|people| Json(people)) | |
.map_err(|error| error_status(error)) | |
} | |
fn error_status(error: Error) -> Failure { | |
Failure(match error { | |
Error::NotFound => Status::NotFound, | |
_ => Status::InternalServerError | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment