Enhance error handling in DbError conversion: Improved the From<PgError> implementation to provide detailed error messages, including SQLSTATE, detail, and hint when available, for better debugging and clarity in database error reporting.
This commit is contained in:
@@ -32,7 +32,19 @@ impl std::error::Error for DbError {}
|
|||||||
|
|
||||||
impl From<PgError> for DbError {
|
impl From<PgError> for DbError {
|
||||||
fn from(err: PgError) -> Self {
|
fn from(err: PgError) -> Self {
|
||||||
DbError::new(format!("Postgres-Fehler: {err}"))
|
if let Some(db_err) = err.as_db_error() {
|
||||||
|
let code = db_err.code();
|
||||||
|
let message = db_err.message();
|
||||||
|
let detail = db_err.detail().unwrap_or_default();
|
||||||
|
let hint = db_err.hint().unwrap_or_default();
|
||||||
|
|
||||||
|
DbError::new(format!(
|
||||||
|
"Postgres-Fehler: {} (SQLSTATE: {}, Detail: {}, Hint: {})",
|
||||||
|
message, code, detail, hint
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
DbError::new(format!("Postgres-Fehler (Client): {err}"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user