diff options
author | Timo Kösters <timo@koesters.xyz> | 2023-08-10 17:01:56 +0000 |
---|---|---|
committer | Timo Kösters <timo@koesters.xyz> | 2023-08-10 17:01:56 +0000 |
commit | 0c2cfda3ae923d9e922d5edf379e4d8976a52d4e (patch) | |
tree | a8a8ecddf12f8ea183fc8f9948d8483648b9e187 /src/utils/error.rs | |
parent | 53f14a2c4c216b529cc63137d8704573197aed19 (diff) | |
parent | 4bf8ee1f7481a222efe87235fa400f6cd14ebd11 (diff) | |
download | conduit-0c2cfda3ae923d9e922d5edf379e4d8976a52d4e.zip |
Merge branch 'next' into 'master'v0.6.0
Merge remote-tracking branch 'origin/next'
See merge request famedly/conduit!538
Diffstat (limited to 'src/utils/error.rs')
-rw-r--r-- | src/utils/error.rs | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/utils/error.rs b/src/utils/error.rs index 4f044ca..6e88cf5 100644 --- a/src/utils/error.rs +++ b/src/utils/error.rs @@ -9,7 +9,7 @@ use ruma::{ OwnedServerName, }; use thiserror::Error; -use tracing::{error, warn}; +use tracing::{error, info}; #[cfg(feature = "persy")] use persy::PersyError; @@ -131,13 +131,35 @@ impl Error { _ => (Unknown, StatusCode::INTERNAL_SERVER_ERROR), }; - warn!("{}: {}", status_code, message); + info!("Returning an error: {}: {}", status_code, message); RumaResponse(UiaaResponse::MatrixError(RumaError { body: ErrorBody::Standard { kind, message }, status_code, })) } + + /// Sanitizes public-facing errors that can leak sensitive information. + pub fn sanitized_error(&self) -> String { + let db_error = String::from("Database or I/O error occurred."); + + match self { + #[cfg(feature = "sled")] + Self::SledError { .. } => db_error, + #[cfg(feature = "sqlite")] + Self::SqliteError { .. } => db_error, + #[cfg(feature = "persy")] + Self::PersyError { .. } => db_error, + #[cfg(feature = "heed")] + Self::HeedError => db_error, + #[cfg(feature = "rocksdb")] + Self::RocksDbError { .. } => db_error, + Self::IoError { .. } => db_error, + Self::BadConfig { .. } => db_error, + Self::BadDatabase { .. } => db_error, + _ => self.to_string(), + } + } } #[cfg(feature = "persy")] |