Consistent error message casing.
This commit is contained in:
@@ -5,14 +5,14 @@ pub mod transactions;
|
|||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum DatabaseError {
|
pub enum DatabaseError {
|
||||||
#[error("Foreign key violation ({constraint}): {source}")]
|
#[error("foreign key violation ({constraint}): {source}")]
|
||||||
ForeignKeyViolation {
|
ForeignKeyViolation {
|
||||||
constraint: Constraint,
|
constraint: Constraint,
|
||||||
#[source]
|
#[source]
|
||||||
source: sqlx::Error,
|
source: sqlx::Error,
|
||||||
},
|
},
|
||||||
|
|
||||||
#[error("Internal error: {0}")]
|
#[error("internal error: {0}")]
|
||||||
Internal(#[source] sqlx::Error),
|
Internal(#[source] sqlx::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,13 +37,13 @@ impl From<sqlx::Error> for DatabaseError {
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
|
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
|
||||||
pub enum Constraint {
|
pub enum Constraint {
|
||||||
#[error("Recurring transaction source account constraint violation")]
|
#[error("recurring transaction source account constraint violation")]
|
||||||
RecurringTransactionSourceAccount,
|
RecurringTransactionSourceAccount,
|
||||||
|
|
||||||
#[error("Recurring transaction destination account constraint violation")]
|
#[error("recurring transaction destination account constraint violation")]
|
||||||
RecurringTransactionDestinationAccount,
|
RecurringTransactionDestinationAccount,
|
||||||
|
|
||||||
#[error("Unknown constraint violation: {0:?}")]
|
#[error("unknown constraint violation: {0:?}")]
|
||||||
Unknown(Option<String>),
|
Unknown(Option<String>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -36,10 +36,10 @@ impl IntoResponse for AppError {
|
|||||||
return error_response(StatusCode::UNPROCESSABLE_ENTITY, error.to_string());
|
return error_response(StatusCode::UNPROCESSABLE_ENTITY, error.to_string());
|
||||||
}
|
}
|
||||||
Self::Repository(RepositoryError::Database(error)) => {
|
Self::Repository(RepositoryError::Database(error)) => {
|
||||||
tracing::error!(%error, "Database query failed");
|
tracing::error!(%error, "database query failed");
|
||||||
}
|
}
|
||||||
Self::Repository(RepositoryError::Decode(error)) => {
|
Self::Repository(RepositoryError::Decode(error)) => {
|
||||||
tracing::error!(%error, "Invalid stored data");
|
tracing::error!(%error, "invalid stored data");
|
||||||
}
|
}
|
||||||
Self::Repository(RepositoryError::ReferenceViolation {
|
Self::Repository(RepositoryError::ReferenceViolation {
|
||||||
relation: ReferenceRelation::SourceAccount,
|
relation: ReferenceRelation::SourceAccount,
|
||||||
@@ -76,7 +76,7 @@ impl IntoResponse for AppError {
|
|||||||
kind,
|
kind,
|
||||||
source,
|
source,
|
||||||
}) => {
|
}) => {
|
||||||
tracing::error!(%relation, %kind, error = ?source, "Unhandled reference violation");
|
tracing::error!(%relation, %kind, error = ?source, "unhandled reference violation");
|
||||||
}
|
}
|
||||||
Self::Repository(RepositoryError::QueryConversion(error)) => {
|
Self::Repository(RepositoryError::QueryConversion(error)) => {
|
||||||
return error_response(StatusCode::BAD_REQUEST, error.to_string());
|
return error_response(StatusCode::BAD_REQUEST, error.to_string());
|
||||||
|
|||||||
+5
-5
@@ -24,24 +24,24 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
.max_connections(5)
|
.max_connections(5)
|
||||||
.connect(&database_url)
|
.connect(&database_url)
|
||||||
.await
|
.await
|
||||||
.context("Failed to connect to database")?;
|
.context("failed to connect to database")?;
|
||||||
|
|
||||||
sqlx::migrate!()
|
sqlx::migrate!()
|
||||||
.run(&pool)
|
.run(&pool)
|
||||||
.await
|
.await
|
||||||
.context("Failed to run database migrations")?;
|
.context("failed to run database migrations")?;
|
||||||
|
|
||||||
let host = env::var("HOST").context("HOST must be set")?;
|
let host = env::var("HOST").context("HOST must be set")?;
|
||||||
let port = env::var("PORT").context("PORT must be set")?;
|
let port = env::var("PORT").context("PORT must be set")?;
|
||||||
let addr = format!("{}:{}", host, port);
|
let addr = format!("{}:{}", host, port);
|
||||||
let listener = TcpListener::bind(&addr)
|
let listener = TcpListener::bind(&addr)
|
||||||
.await
|
.await
|
||||||
.context(format!("Failed to bind to address: {}", addr))?;
|
.context(format!("failed to bind to address: {}", addr))?;
|
||||||
|
|
||||||
tracing::info!(%addr, "Starting server");
|
tracing::info!(%addr, "starting server");
|
||||||
axum::serve(listener, routes::create_router(pool).into_make_service())
|
axum::serve(listener, routes::create_router(pool).into_make_service())
|
||||||
.await
|
.await
|
||||||
.context("Server stopped unexpectedly")?;
|
.context("server stopped unexpectedly")?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,9 +76,9 @@ pub enum ReferenceViolationKind {
|
|||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum QueryConversionError {
|
pub enum QueryConversionError {
|
||||||
#[error("Failed to convert limit: {0}")]
|
#[error("failed to convert limit: {0}")]
|
||||||
Limit(u64),
|
Limit(u64),
|
||||||
|
|
||||||
#[error("Failed to convert offset: {0}")]
|
#[error("failed to convert offset: {0}")]
|
||||||
Offset(u64),
|
Offset(u64),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user