aboutsummaryrefslogtreecommitdiffstats
path: root/rust/src/errors.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-01-29 12:50:39 -0800
committerBryan Newbold <bnewbold@robocracy.org>2019-01-29 12:50:39 -0800
commit5aac6ec1a46a64b810f4695de968a10cab000914 (patch)
treec3086929fbd27c596dd95c5c8434eabc9d6363c8 /rust/src/errors.rs
parent6f8410f4f77a7724081e5573f904bebb3b68b7c1 (diff)
downloadfatcat-5aac6ec1a46a64b810f4695de968a10cab000914.tar.gz
fatcat-5aac6ec1a46a64b810f4695de968a10cab000914.zip
better database NotFound error propagation
Diffstat (limited to 'rust/src/errors.rs')
-rw-r--r--rust/src/errors.rs8
1 files changed, 5 insertions, 3 deletions
diff --git a/rust/src/errors.rs b/rust/src/errors.rs
index 08e79d51..cb53e6d1 100644
--- a/rust/src/errors.rs
+++ b/rust/src/errors.rs
@@ -85,6 +85,10 @@ pub enum FatcatError {
// Diesel constraint that we think is a user error
ConstraintViolation(String),
+ #[fail(display = "generic database 'not-found'")]
+ // This should generally get caught and handled
+ DatabaseRowNotFound,
+
// TODO: can these hold context instead of Inner?
#[fail(display = "unexpected database error: {}", _0)]
// other Diesel, R2d2 errors which we don't think are user errors (eg, connection failure)
@@ -112,9 +116,7 @@ impl Into<models::ErrorResponse> for FatcatError {
impl From<diesel::result::Error> for FatcatError {
fn from(inner: diesel::result::Error) -> FatcatError {
match inner {
- diesel::result::Error::NotFound => {
- FatcatError::NotFound("unknown".to_string(), "N/A".to_string())
- }
+ diesel::result::Error::NotFound => FatcatError::DatabaseRowNotFound,
diesel::result::Error::DatabaseError(_, _) => {
FatcatError::ConstraintViolation(inner.to_string())
}