Improve error handling
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
use axum::{extract::{State, Path}, Json};
|
||||
use sqlx::PgPool;
|
||||
|
||||
use crate::error::AppError;
|
||||
use crate::error::Error;
|
||||
use crate::models::item::{create_item, get_item, CreateItem, Item};
|
||||
|
||||
pub async fn get(
|
||||
State(pool): State<PgPool>,
|
||||
Path(id): Path<i32>,
|
||||
) -> Result<Json<Item>, AppError> {
|
||||
) -> Result<Json<Item>, Error> {
|
||||
Ok(Json(get_item(pool, id).await?))
|
||||
}
|
||||
|
||||
pub async fn post(
|
||||
State(pool): State<PgPool>,
|
||||
Json(payload): Json<CreateItem>,
|
||||
) -> Result<Json<Item>, AppError> {
|
||||
) -> Result<Json<Item>, Error> {
|
||||
Ok(Json(create_item(pool, payload).await?))
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use axum::{extract::State, Json};
|
||||
use sqlx::PgPool;
|
||||
|
||||
use crate::error::AppError;
|
||||
use crate::error::Error;
|
||||
use crate::models::item::{get_items, Item};
|
||||
|
||||
pub async fn get(State(pool): State<PgPool>) -> Result<Json<Vec<Item>>, AppError> {
|
||||
pub async fn get(State(pool): State<PgPool>) -> Result<Json<Vec<Item>>, Error> {
|
||||
Ok(Json(get_items(pool).await?))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user