From 43fde903879a63009a54edbbfce56f132521ed82 Mon Sep 17 00:00:00 2001 From: Serra Allgood Date: Mon, 5 Oct 2020 20:17:30 -0700 Subject: [PATCH] Fix displaying not found page when submitting a duplicated blocklist email Signed-off-by: Serra Allgood --- src/routes/instance.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/routes/instance.rs b/src/routes/instance.rs index 72d41c3f..3d469ee2 100644 --- a/src/routes/instance.rs +++ b/src/routes/instance.rs @@ -210,11 +210,19 @@ pub fn add_email_blocklist( form: LenientForm, rockets: PlumeRocket, ) -> Result, ErrorPage> { - BlocklistedEmail::insert(&*rockets.conn, form.0)?; - Ok(Flash::success( - Redirect::to(uri!(admin_email_blocklist: page = None)), - i18n!(rockets.intl.catalog, "Email Blocked"), - )) + let result = BlocklistedEmail::insert(&*rockets.conn, form.0); + + if let Err(Error::Db(_)) = result { + Ok(Flash::error( + Redirect::to(uri!(admin_email_blocklist: page = None)), + i18n!(rockets.intl.catalog, "Email already blocked") + )) + } else { + Ok(Flash::success( + Redirect::to(uri!(admin_email_blocklist: page = None)), + i18n!(rockets.intl.catalog, "Email Blocked"), + )) + } } #[get("/admin/emails?")] pub fn admin_email_blocklist(