From 4e68293450fbfb2a342994fff1ada446fd9a4eb6 Mon Sep 17 00:00:00 2001 From: Antoine Gersant Date: Sun, 11 Nov 2018 11:19:28 -0800 Subject: [PATCH] Simplified error syntax --- src/api.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api.rs b/src/api.rs index 2f97847..d28b47f 100644 --- a/src/api.rs +++ b/src/api.rs @@ -236,7 +236,7 @@ fn auth( ) -> Result, errors::Error> { if !user::auth::(&db, &credentials.username, &credentials.password)? { - return Err(errors::Error::from(errors::ErrorKind::IncorrectCredentials)) + bail!(errors::ErrorKind::IncorrectCredentials) } cookies.add_private(get_session_cookie(&credentials.username)); @@ -412,19 +412,19 @@ fn lastfm_link( // Percent decode let base64_content = match RawStr::from_str(&content).percent_decode() { Ok(s) => s, - Err(_) => return Err(errors::Error::from(errors::ErrorKind::EncodingError).into()), + Err(_) => bail!(errors::ErrorKind::EncodingError), }; // Base64 decode let popup_content = match base64::decode(base64_content.as_bytes()) { Ok(c) => c, - Err(_) => return Err(errors::Error::from(errors::ErrorKind::EncodingError).into()), + Err(_) => bail!(errors::ErrorKind::EncodingError), }; // UTF-8 decode let popup_content_string = match str::from_utf8(&popup_content) { Ok(s) => s, - Err(_) => return Err(errors::Error::from(errors::ErrorKind::EncodingError).into()), + Err(_) => bail!(errors::ErrorKind::EncodingError), }; Ok(Html(popup_content_string.to_string()))