Use Result<Option<_>, _>

This commit is contained in:
philippeitis
2022-10-16 21:04:43 -07:00
parent 1132b542d2
commit a375b710b1
3 changed files with 62 additions and 46 deletions

View File

@@ -399,7 +399,7 @@ match result {
Error::HttpError(_)
|Error::Io(_)
|Error::MissingAPIKey
|Error::MissingToken
|Error::MissingToken(_)
|Error::Cancelled
|Error::UploadSizeLimitExceeded(_, _)
|Error::Failure(_)
@@ -711,13 +711,13 @@ else {
loop {
% if default_scope:
let token = match ${auth_call}.get_token(&self.${api.properties.scopes}.iter().map(String::as_str).collect::<Vec<_>>()[..]).await {
Some(token) => token.clone(),
None => {
match dlg.token() {
Some(token) => token,
None => {
Ok(token) => token,
Err(e) => {
match dlg.token(e) {
Ok(token) => token,
Err(e) => {
${delegate_finish}(false);
return Err(client::Error::MissingToken);
return Err(client::Error::MissingToken(e));
}
}
}
@@ -756,11 +756,13 @@ else {
let client = &self.hub.client;
dlg.pre_request();
let mut req_builder = hyper::Request::builder().method(${method_name_to_variant(m.httpMethod)}).uri(url.clone().into_string())
.header(USER_AGENT, self.hub._user_agent.clone())\
% if default_scope:
.header(AUTHORIZATION, format!("Bearer {}", token.as_str()))\
% endif
;
.header(USER_AGENT, self.hub._user_agent.clone());
% if default_scope:
if let Some(token) = token.as_ref() {
req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
}
% endif
% if resumable_media_param:
upload_url_from_server = true;
@@ -854,7 +856,7 @@ else {
start_at: if upload_url_from_server { Some(0) } else { None },
auth: &${auth_call},
user_agent: &self.hub._user_agent,
auth_header: format!("Bearer {}", token.as_str()),
auth_header: format!("Bearer {}", token.expect("resumable upload requires token").as_str()),
url: url_str,
reader: &mut reader,
media_type: reader_mime_type.clone(),