summaryrefslogtreecommitdiffstats
path: root/rust/src/errors.rs
diff options
context:
space:
mode:
authorbnewbold <bnewbold@archive.org>2022-01-25 19:36:44 +0000
committerbnewbold <bnewbold@archive.org>2022-01-25 19:36:44 +0000
commitdb489fa78e80615e61b6857b8262bf5ab44fd10f (patch)
treef342980017142454bcaac111c9b8d098f0be73fa /rust/src/errors.rs
parentd2175fa8ecd598b391c84d43b3ebe2ef8903a997 (diff)
parent709c975077615d9af9694784da50a8b4b30e4706 (diff)
downloadfatcat-db489fa78e80615e61b6857b8262bf5ab44fd10f.tar.gz
fatcat-db489fa78e80615e61b6857b8262bf5ab44fd10f.zip
Merge branch 'bnewbold-read-only' into 'master'
read-only database mode See merge request webgroup/fatcat!137
Diffstat (limited to 'rust/src/errors.rs')
-rw-r--r--rust/src/errors.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/rust/src/errors.rs b/rust/src/errors.rs
index e18e660f..ea0f9646 100644
--- a/rust/src/errors.rs
+++ b/rust/src/errors.rs
@@ -81,10 +81,13 @@ pub enum FatcatError {
// Utf8Decode, StringDecode, Uuid
BadRequest(String),
- #[fail(display = "unexpected database error: {}", _0)]
+ #[fail(display = "database error: {}", _0)]
// Diesel constraint that we think is a user error
ConstraintViolation(String),
+ #[fail(display = "database in read-only mode (usually replica or maintenance)")]
+ DatabaseReadOnly,
+
#[fail(display = "generic database 'not-found'")]
// This should generally get caught and handled
DatabaseRowNotFound,
@@ -117,6 +120,11 @@ impl From<diesel::result::Error> for FatcatError {
fn from(inner: diesel::result::Error) -> FatcatError {
match inner {
diesel::result::Error::NotFound => FatcatError::DatabaseRowNotFound,
+ diesel::result::Error::DatabaseError(_, info)
+ if info.message().contains("in a read-only transaction") =>
+ {
+ FatcatError::DatabaseReadOnly
+ }
diesel::result::Error::DatabaseError(_, _) => {
FatcatError::ConstraintViolation(inner.to_string())
}