initial commit

This commit is contained in:
2025-07-04 11:56:23 +08:00
commit 0cf47db3e8
9 changed files with 361 additions and 0 deletions

34
src/errors.rs Normal file
View File

@@ -0,0 +1,34 @@
use axum::{
http::StatusCode,
response::{IntoResponse, Response},
};
use sqlx::Error as SqlxError;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum AppError {
#[error("Account not found: {0}")]
AccountNotFound(i64),
#[error("Account already exists")]
AccountAlreadyExists,
#[error("Insufficient funds")]
InsufficientFunds,
#[error("Database error: {0}")]
DatabaseError(#[from] SqlxError),
#[error("Invalid input: {0}")]
InvalidInput(String),
}
impl IntoResponse for AppError {
fn into_response(self) -> Response {
let status = match self {
AppError::AccountNotFound(_) => StatusCode::NOT_FOUND,
AppError::InsufficientFunds => StatusCode::BAD_REQUEST,
AppError::AccountAlreadyExists => StatusCode::BAD_REQUEST,
AppError::DatabaseError(_) => StatusCode::INTERNAL_SERVER_ERROR,
AppError::InvalidInput(_) => StatusCode::BAD_REQUEST,
};
(status, self.to_string()).into_response()
}
}