Skip to content

Commit

Permalink
fix(JsonError): make error field non-optional
Browse files Browse the repository at this point in the history
* to makes using the structure much easier.
* incremented version

Fixes #6
  • Loading branch information
Byron committed May 2, 2015
1 parent b08b239 commit a395fe8
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
}
Expand Down
9 changes: 3 additions & 6 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
}
Expand Down Expand Up @@ -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))
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit a395fe8

Please sign in to comment.