Skip to content

Commit eef1471

Browse files
committed
feat(doit): json decode and delegation
Now json errors are handled and delegated with the option to retry, and all other values are just decoded according to plan. For now, I brutally unwrap json values assuming this will work, because it really should work.
1 parent 2c79f6e commit eef1471

5 files changed

Lines changed: 1189 additions & 730 deletions

File tree

gen/youtube3/src/cmn.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl<T: Seek + Read> ReadSeek for T {}
4242

4343
/// A utility type which can decode a server response that indicates error
4444
#[derive(RustcDecodable)]
45-
struct JsonServerError {
45+
pub struct JsonServerError {
4646
error: String,
4747
error_description: Option<String>
4848
}
@@ -68,6 +68,22 @@ pub trait Delegate {
6868
fn api_key(&mut self) -> Option<String> {
6969
None
7070
}
71+
72+
/// Called whenever the Authenticator didn't yield a token. The delegate
73+
/// may attempt to provide one, or just take is a general information about the
74+
/// pending impending failure
75+
fn token(&mut self) -> Option<oauth2::Token> {
76+
None
77+
}
78+
79+
/// Called whenever the http request returns with a non-success status code.
80+
/// This can involve authentication issues, or anything else that very much
81+
/// depends on the used API method.
82+
/// The delegate should check the status, header and decoded json error to decide
83+
/// whether to retry or not. In the latter case, the underlying call will fail.
84+
fn http_failure(&mut self, _: &hyper::client::Response, JsonServerError) -> oauth2::Retry {
85+
oauth2::Retry::Abort
86+
}
7187
}
7288

7389
#[derive(Default)]
@@ -91,6 +107,9 @@ pub enum Result<T = ()> {
91107
/// An additional, free form field clashed with one of the built-in optional ones
92108
FieldClash(&'static str),
93109

110+
/// Indicates an HTTP repsonse with a non-success status code
111+
Failure(hyper::client::Response),
112+
94113
/// It worked !
95114
Success(T),
96115
}

0 commit comments

Comments
 (0)