Simplified error syntax

This commit is contained in:
Antoine Gersant 2018-11-11 11:19:28 -08:00
parent 2cbc1645ee
commit 4e68293450

View file

@ -236,7 +236,7 @@ fn auth(
) -> Result<Json<AuthOutput>, errors::Error> { ) -> Result<Json<AuthOutput>, errors::Error> {
if !user::auth::<DB>(&db, &credentials.username, &credentials.password)? { if !user::auth::<DB>(&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)); cookies.add_private(get_session_cookie(&credentials.username));
@ -412,19 +412,19 @@ fn lastfm_link(
// Percent decode // Percent decode
let base64_content = match RawStr::from_str(&content).percent_decode() { let base64_content = match RawStr::from_str(&content).percent_decode() {
Ok(s) => s, Ok(s) => s,
Err(_) => return Err(errors::Error::from(errors::ErrorKind::EncodingError).into()), Err(_) => bail!(errors::ErrorKind::EncodingError),
}; };
// Base64 decode // Base64 decode
let popup_content = match base64::decode(base64_content.as_bytes()) { let popup_content = match base64::decode(base64_content.as_bytes()) {
Ok(c) => c, Ok(c) => c,
Err(_) => return Err(errors::Error::from(errors::ErrorKind::EncodingError).into()), Err(_) => bail!(errors::ErrorKind::EncodingError),
}; };
// UTF-8 decode // UTF-8 decode
let popup_content_string = match str::from_utf8(&popup_content) { let popup_content_string = match str::from_utf8(&popup_content) {
Ok(s) => s, 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())) Ok(Html(popup_content_string.to_string()))