diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2022-01-21 16:42:58 -0800 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2022-01-21 16:52:03 -0800 |
commit | c8b2d48106f92215ca2fbd761f8ac4cf254135e6 (patch) | |
tree | e61b3659baa0ad14a87f35e7e6e9769f9d248563 /rust/src/errors.rs | |
parent | 817b0e76d4b9f5b22e08e90e946af1c14b6cc3e6 (diff) | |
download | fatcat-c8b2d48106f92215ca2fbd761f8ac4cf254135e6.tar.gz fatcat-c8b2d48106f92215ca2fbd761f8ac4cf254135e6.zip |
rust: handle database read-only mode (as 5xx errors, not 4xx)
Diffstat (limited to 'rust/src/errors.rs')
-rw-r--r-- | rust/src/errors.rs | 10 |
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()) } |