From a395fe892c9893360305f93de60b61cbc64162f9 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 2 May 2015 09:06:57 +0200 Subject: [PATCH] fix(JsonError): make `error` field non-optional * to makes using the structure much easier. * incremented version Fixes #6 --- Cargo.toml | 2 +- src/common.rs | 2 +- src/device.rs | 9 +++------ src/refresh.rs | 6 ++---- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 78b4a6f13..7ff1a5cb2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "yup-oauth2" -version = "0.4.2" +version = "0.4.3" authors = ["Sebastian Thiel "] repository = "https://github.com/Byron/yup-oauth2" description = "A partial oauth2 implementation, providing the 'device' authorization flow" diff --git a/src/common.rs b/src/common.rs index cd7cbd3ee..aacc62eac 100644 --- a/src/common.rs +++ b/src/common.rs @@ -10,7 +10,7 @@ pub trait Flow { #[derive(Deserialize)] pub struct JsonError { - pub error: Option, + pub error: String, pub error_description: Option, pub error_uri: Option, } diff --git a/src/device.rs b/src/device.rs index 61012cf3d..4aaf315b7 100644 --- a/src/device.rs +++ b/src/device.rs @@ -84,13 +84,12 @@ pub enum RequestError { impl From 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 DeviceFlow match json::from_str::(&json_str) { Err(_) => {}, // ignore, move on Ok(res) => { - if res.error.is_some() { - return Err(RequestError::from(res)) - } + return Err(RequestError::from(res)) } } diff --git a/src/refresh.rs b/src/refresh.rs index 6da144867..aed0837bb 100644 --- a/src/refresh.rs +++ b/src/refresh.rs @@ -98,10 +98,8 @@ impl RefreshFlow match json::from_str::(&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; } }