mirror of
https://github.com/actix/examples
synced 2024-11-23 22:41:07 +01:00
fix db error messages (#353)
Make the error messages for failed Database operations specific to their operation.
This commit is contained in:
parent
5b98f85afd
commit
bd2a0bb8fd
@ -18,7 +18,7 @@ fn get_conn(pool: &PgPool) -> Result<PgPooledConnection, &'static str> {
|
||||
}
|
||||
|
||||
pub fn get_all_tasks(pool: &PgPool) -> Result<Vec<Task>, &'static str> {
|
||||
Task::all(get_conn(pool)?.deref()).map_err(|_| "Error inserting task")
|
||||
Task::all(get_conn(pool)?.deref()).map_err(|_| "Error retrieving tasks")
|
||||
}
|
||||
|
||||
pub fn create_task(todo: String, pool: &PgPool) -> Result<(), &'static str> {
|
||||
@ -31,11 +31,11 @@ pub fn create_task(todo: String, pool: &PgPool) -> Result<(), &'static str> {
|
||||
pub fn toggle_task(id: i32, pool: &PgPool) -> Result<(), &'static str> {
|
||||
Task::toggle_with_id(id, get_conn(pool)?.deref())
|
||||
.map(|_| ())
|
||||
.map_err(|_| "Error inserting task")
|
||||
.map_err(|_| "Error toggling task completion")
|
||||
}
|
||||
|
||||
pub fn delete_task(id: i32, pool: &PgPool) -> Result<(), &'static str> {
|
||||
Task::delete_with_id(id, get_conn(pool)?.deref())
|
||||
.map(|_| ())
|
||||
.map_err(|_| "Error inserting task")
|
||||
.map_err(|_| "Error deleting task")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user