mirror of
https://github.com/OMGeeky/yup-oauth2.git
synced 2026-02-23 15:50:00 +01:00
fix(JsonError): make error field non-optional
* to makes using the structure much easier. * incremented version Fixes #6
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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>,
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user