Move the error_status function to the rest_helpers module

This commit is contained in:
Paul van Tilburg 2019-06-21 21:03:42 +02:00
parent 95dd4408b7
commit f0764a30fb
2 changed files with 13 additions and 8 deletions

View File

@ -3,7 +3,6 @@
//! Handlers for viewing a list of existing customers or creating a new one.
use diesel::prelude::*;
use diesel::result::Error as DieselError;
use rocket::http::Status;
use rocket::response::status::Created;
use rocket::uri;
@ -11,18 +10,12 @@ use rocket::{delete, get, post, put};
use rocket_contrib::json::Json;
use crate::models::{Customer, NewCustomer};
use crate::rest_helpers::error_status;
use crate::DbConn;
pub mod invoices;
pub mod tasks;
fn error_status(error: DieselError) -> Status {
match error {
DieselError::NotFound => Status::NotFound,
_ => Status::InternalServerError,
}
}
/// Shows the list of customers.
#[get("/")]
pub fn index(conn: DbConn) -> Result<Json<Vec<Customer>>, Status> {

View File

@ -1,3 +1,15 @@
use diesel::result::Error as QueryError;
use rocket::http::Status;
/// Returns a Rocket status for the provided Diesel (query) error.
pub fn error_status(error: QueryError) -> Status {
dbg!(&error);
match error {
QueryError::NotFound => Status::NotFound,
_ => Status::InternalServerError,
}
}
macro_rules! all {
($model_name:ident, $conn:expr) => {{
use diesel::associations::HasTable;