NotFound error and add validation

This commit is contained in:
2023-05-07 19:50:44 -04:00
parent de157a3b1e
commit f30be5f451
3 changed files with 26 additions and 8 deletions

View File

@@ -21,8 +21,13 @@ pub enum Error {
#[error("validation error in request body")]
InvalidEntity(#[from] ValidationErrors),
#[error("{0} not found")]
NotFound(&'static str),
}
pub type Result<T, E = Error> = ::std::result::Result<T, E>;
impl IntoResponse for Error {
fn into_response(self) -> Response {
#[serde_with::serde_as]
@@ -59,7 +64,7 @@ impl Error {
use Error::*;
match self {
Sqlx(sqlx::Error::RowNotFound) => StatusCode::NOT_FOUND,
NotFound(_) => StatusCode::NOT_FOUND,
Sqlx(_) | Anyhow(_) => StatusCode::INTERNAL_SERVER_ERROR,
InvalidEntity(_) => StatusCode::UNPROCESSABLE_ENTITY,
}