Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1215)

Unified Diff: utils/pub/oauth2.dart

Issue 11569046: Add a pub command for managing uploaders for packages. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
+ }
});
}

Powered by Google App Engine
This is Rietveld 408576698