fix(api): correct AppError variant semantics for transaction/query errors

- client.transaction() failures: db_conn -> tx (logs correct category)
- auth session INSERT: db_conn -> query
- delete_post UPDATE: tx -> query (no transaction context)
This commit is contained in:
xfy 2026-06-10 13:19:57 +08:00
parent a3fa602df2
commit bf401e4916
2 changed files with 4 additions and 4 deletions

View File

@ -196,7 +196,7 @@ pub async fn login(username: String, password: String) -> Result<AuthResponse, S
&[&user_id, &token, &expires_at],
)
.await
.map_err(AppError::db_conn)?;
.map_err(AppError::query)?;
let cookie = format!(
"session={token}; HttpOnly; Path=/; Max-Age={}; SameSite=Lax",

View File

@ -263,7 +263,7 @@ pub async fn create_post(
None
};
let tx = client.transaction().await.map_err(AppError::db_conn)?;
let tx = client.transaction().await.map_err(AppError::tx)?;
let row = tx
.query_one(
@ -411,7 +411,7 @@ pub async fn update_post(
let post_status = PostStatus::from_str(&status).unwrap_or(PostStatus::Draft);
let cover_image = cover_image.filter(|s| !s.trim().is_empty());
let tx = client.transaction().await.map_err(AppError::db_conn)?;
let tx = client.transaction().await.map_err(AppError::tx)?;
let old_tags: Vec<String> = {
let rows = tx
@ -715,7 +715,7 @@ pub async fn delete_post(post_id: i32) -> Result<CreatePostResponse, ServerFnErr
&[&post_id],
)
.await
.map_err(AppError::tx)?;
.map_err(AppError::query)?;
if result == 0 {
return Ok(CreatePostResponse {