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:
parent
a3fa602df2
commit
bf401e4916
@ -196,7 +196,7 @@ pub async fn login(username: String, password: String) -> Result<AuthResponse, S
|
|||||||
&[&user_id, &token, &expires_at],
|
&[&user_id, &token, &expires_at],
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.map_err(AppError::db_conn)?;
|
.map_err(AppError::query)?;
|
||||||
|
|
||||||
let cookie = format!(
|
let cookie = format!(
|
||||||
"session={token}; HttpOnly; Path=/; Max-Age={}; SameSite=Lax",
|
"session={token}; HttpOnly; Path=/; Max-Age={}; SameSite=Lax",
|
||||||
|
|||||||
@ -263,7 +263,7 @@ pub async fn create_post(
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let tx = client.transaction().await.map_err(AppError::db_conn)?;
|
let tx = client.transaction().await.map_err(AppError::tx)?;
|
||||||
|
|
||||||
let row = tx
|
let row = tx
|
||||||
.query_one(
|
.query_one(
|
||||||
@ -411,7 +411,7 @@ pub async fn update_post(
|
|||||||
let post_status = PostStatus::from_str(&status).unwrap_or(PostStatus::Draft);
|
let post_status = PostStatus::from_str(&status).unwrap_or(PostStatus::Draft);
|
||||||
let cover_image = cover_image.filter(|s| !s.trim().is_empty());
|
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 old_tags: Vec<String> = {
|
||||||
let rows = tx
|
let rows = tx
|
||||||
@ -715,7 +715,7 @@ pub async fn delete_post(post_id: i32) -> Result<CreatePostResponse, ServerFnErr
|
|||||||
&[&post_id],
|
&[&post_id],
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.map_err(AppError::tx)?;
|
.map_err(AppError::query)?;
|
||||||
|
|
||||||
if result == 0 {
|
if result == 0 {
|
||||||
return Ok(CreatePostResponse {
|
return Ok(CreatePostResponse {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user