fix(JsonError): make error field non-optional

* to makes using the structure much easier.
* incremented version

Fixes #6
This commit is contained in:
Sebastian Thiel
2015-05-02 09:06:57 +02:00
parent b08b239e88
commit a395fe892c
4 changed files with 7 additions and 12 deletions

View File

@@ -1,7 +1,7 @@
[package]
name = "yup-oauth2"
version = "0.4.2"
version = "0.4.3"
authors = ["Sebastian Thiel <byronimo@gmail.com>"]
repository = "https://github.com/Byron/yup-oauth2"
description = "A partial oauth2 implementation, providing the 'device' authorization flow"

View File

@@ -10,7 +10,7 @@ pub trait Flow {
#[derive(Deserialize)]
pub struct JsonError {
pub error: Option<String>,
pub error: String,
pub error_description: Option<String>,
pub error_uri: Option<String>,
}

View File

@@ -84,13 +84,12 @@ pub enum RequestError {
impl From<JsonError> for RequestError {
fn from(value: JsonError) -> RequestError {
let err_str = value.error.unwrap();
match &*err_str {
match &*value.error {
"invalid_client" => RequestError::InvalidClient,
"invalid_scope" => RequestError::InvalidScope(
value.error_description.unwrap_or("no description provided".to_string())
),
_ => RequestError::NegativeServerResponse(err_str, value.error_description),
_ => RequestError::NegativeServerResponse(value.error, value.error_description),
}
}
}
@@ -219,9 +218,7 @@ impl<C> DeviceFlow<C>
match json::from_str::<JsonError>(&json_str) {
Err(_) => {}, // ignore, move on
Ok(res) => {
if res.error.is_some() {
return Err(RequestError::from(res))
}
return Err(RequestError::from(res))
}
}

View File

@@ -98,10 +98,8 @@ impl<C> RefreshFlow<C>
match json::from_str::<JsonError>(&json_str) {
Err(_) => {},
Ok(res) => {
if let Some(err) = res.error {
self.result = RefreshResult::RefreshError(err, res.error_description);
return &self.result;
}
self.result = RefreshResult::RefreshError(res.error, res.error_description);
return &self.result;
}
}