mirror of
https://github.com/OMGeeky/yup-oauth2.git
synced 2025-12-31 16:40:05 +01:00
refactor(StringError): Take more comfortable types in StringError::new
Follow up to #77.
This commit is contained in:
@@ -255,7 +255,7 @@ where
|
||||
Err(err) => err.to_string(),
|
||||
};
|
||||
return Err(Box::new(StringError::new(
|
||||
storage_err + err_str,
|
||||
&(storage_err + err_str),
|
||||
err_description.as_ref(),
|
||||
)));
|
||||
}
|
||||
|
||||
@@ -306,8 +306,8 @@ where
|
||||
|| token.expires_in.is_none()
|
||||
{
|
||||
Err(Box::new(StringError::new(
|
||||
"Token response lacks fields".to_string(),
|
||||
Some(&format!("{:?}", token)),
|
||||
"Token response lacks fields",
|
||||
Some(format!("{:?}", token).as_str()),
|
||||
)))
|
||||
} else {
|
||||
Ok(token.to_oauth_token())
|
||||
|
||||
@@ -88,11 +88,11 @@ impl fmt::Display for StringError {
|
||||
}
|
||||
|
||||
impl StringError {
|
||||
pub fn new(error: String, desc: Option<&String>) -> StringError {
|
||||
let mut error = error;
|
||||
pub fn new<S: AsRef<str>>(error: S, desc: Option<S>) -> StringError {
|
||||
let mut error = error.as_ref().to_string();
|
||||
if let Some(d) = desc {
|
||||
error.push_str(": ");
|
||||
error.push_str(&*d);
|
||||
error.push_str(d.as_ref());
|
||||
}
|
||||
|
||||
StringError { error: error }
|
||||
|
||||
Reference in New Issue
Block a user