From 5aac6ec1a46a64b810f4695de968a10cab000914 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 29 Jan 2019 12:50:39 -0800 Subject: better database NotFound error propagation --- rust/src/errors.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'rust/src/errors.rs') 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 for FatcatError { impl From 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()) } -- cgit v1.2.3