imp(ServiceAccountAccess): Print exact error if server returns one.

Prevents #76.
This commit is contained in:
Lewin Bormann
2019-06-13 16:16:08 +02:00
parent 6b05056b05
commit f034b8bea4
2 changed files with 11 additions and 3 deletions

View File

@@ -16,7 +16,7 @@ use std::error;
use std::sync::{Arc, Mutex};
use crate::storage::{hash_scopes, MemoryStorage, TokenStorage};
use crate::types::{ApplicationSecret, GetToken, StringError, Token};
use crate::types::{ApplicationSecret, GetToken, JsonError, StringError, Token};
use futures::stream::Stream;
use futures::{future, prelude::*};
@@ -283,7 +283,15 @@ impl<'a, C: 'static + hyper::client::connect::Connect> ServiceAccountAccess<C> {
})
.map(|c| String::from_utf8(c.into_bytes().to_vec()).unwrap())
.and_then(|s| {
serde_json::from_str(&s).map_err(|e| Box::new(e) as Box<dyn error::Error + Send>)
if let Ok(jse) = serde_json::from_str::<JsonError>(&s) {
Err(
Box::new(StringError::new(jse.error, jse.error_description.as_ref()))
as Box<dyn error::Error + Send>,
)
} else {
serde_json::from_str(&s)
.map_err(|e| Box::new(e) as Box<dyn error::Error + Send>)
}
})
.then(
|token: Result<TokenResponse, Box<dyn error::Error + Send>>| match token {

View File

@@ -11,7 +11,7 @@ pub trait Flow {
fn type_id() -> FlowType;
}
#[derive(Deserialize)]
#[derive(Deserialize, Debug)]
pub struct JsonError {
pub error: String,
pub error_description: Option<String>,