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