callWithReauth runs fn, re-authenticating once and retrying on an expired session.
( io *iostreams.IOStreams, client *dashboard.Client, token *string, label string, fn func(token string) error, )
| 467 | |
| 468 | // callWithReauth runs fn, re-authenticating once and retrying on an expired session. |
| 469 | func callWithReauth( |
| 470 | io *iostreams.IOStreams, |
| 471 | client *dashboard.Client, |
| 472 | token *string, |
| 473 | label string, |
| 474 | fn func(token string) error, |
| 475 | ) error { |
| 476 | io.StartProgressIndicatorWithLabel(label) |
| 477 | err := fn(*token) |
| 478 | io.StopProgressIndicator() |
| 479 | if err == nil { |
| 480 | return nil |
| 481 | } |
| 482 | |
| 483 | newToken, reAuthErr := auth.ReauthenticateIfExpired(io, client, err) |
| 484 | if reAuthErr != nil { |
| 485 | return reAuthErr |
| 486 | } |
| 487 | *token = newToken |
| 488 | |
| 489 | io.StartProgressIndicatorWithLabel(label) |
| 490 | err = fn(*token) |
| 491 | io.StopProgressIndicator() |
| 492 | return err |
| 493 | } |
no test coverage detected