Chromium Code Reviews| Index: utils/pub/oauth2.dart |
| diff --git a/utils/pub/oauth2.dart b/utils/pub/oauth2.dart |
| index ec3d745f2d2a29af175592cc10d985102edfb6c6..bd8fc7826bd49ab9d4fc9615be739a1fdaaa5a0e 100644 |
| --- a/utils/pub/oauth2.dart |
| +++ b/utils/pub/oauth2.dart |
| @@ -62,7 +62,8 @@ Future clearCredentials(SystemCache cache) { |
| /// the [Future] returned by [fn] completes. |
| /// |
| /// This takes care of loading and saving the client's credentials, as well as |
| -/// prompting the user for their authorization. |
| +/// prompting the user for their authorization. It will also re-authorize and |
| +/// re-run [fn] if a recoverable authorization error is detected. |
| Future withClient(SystemCache cache, Future fn(Client client)) { |
| return _getClient(cache).chain((client) { |
| var completer = new Completer(); |
| @@ -82,6 +83,19 @@ Future withClient(SystemCache cache, Future fn(Client client)) { |
| } |
| }); |
| return completer.future; |
| + }).transformException((e) { |
| + if (e is ExpirationException) { |
| + log.error("Pub's authorization to upload packages has expired and " |
| + "can't be automatically refreshed."); |
| + return withClient(cache, fn); |
|
Bob Nystrom
2012/12/17 18:41:58
Do we need to guard against getting stuck in an in
nweiz
2012/12/17 21:18:48
I don't think so -- even if the server keeps sendi
|
| + } else if (e is AuthorizationException) { |
| + var message = "OAuth2 authorization failed"; |
| + if (e.description != null) message = "$message (${e.description})"; |
| + log.error("$message."); |
| + return clearCredentials(cache).chain((_) => withClient(cache, fn)); |
| + } else { |
| + throw e; |
| + } |
| }); |
| } |