1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#[macro_export]
macro_rules! do_client {
    ($obj:ident, $block:block) => {
        'end: loop {
            if let Some(expires) = $obj.config.access_token_expires_at() {
                if expires - chrono::Duration::hours(1) < chrono::Local::now().naive_utc() {
                    $obj.refresh_access_token().await?;
                }
            }

            match $block.await {
                Ok(t) => {
                    break 'end Ok(t);
                }
                Err(e) => match e {
                    ClientError::InvalidToken => {
                        $obj.refresh_access_token().await?;
                    }
                    _ => break 'end Err(e),
                },
            }
        }
    };
}