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

Unified Diff: utils/pub/command_lish.dart

Issue 11416352: Handle OAuth2 AuthorizationExceptions in pub. (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
« no previous file with comments | « no previous file | utils/pub/io.dart » ('j') | utils/tests/pub/pub_lish_test.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/command_lish.dart
diff --git a/utils/pub/command_lish.dart b/utils/pub/command_lish.dart
index c2def2f15208b7cf61ba34169253dd5c8c43fb15..883bb2136e319f025a0e8ff5ac57814e636b451e 100644
--- a/utils/pub/command_lish.dart
+++ b/utils/pub/command_lish.dart
@@ -36,17 +36,8 @@ class LishCommand extends PubCommand {
Future onRun() {
var cloudStorageUrl;
return oauth2.withClient(cache, (client) {
- // TODO(nweiz): Better error-handling. There are a few cases we need to
- // handle better:
- //
- // * The server can tell us we need new credentials (a 401 error). The
- // oauth2 package should throw an AuthorizationException in this case
- // (contingent on issue 6813 and 6275). We should have the user
- // re-authorize the client, then restart the command. We should also do
- // this in case of an ExpirationException. See issue 6950.
- //
- // * Cloud Storage can provide an XML-formatted error. We should report
- // that error and exit.
+ // TODO(nweiz): Cloud Storage can provide an XML-formatted error. We
+ // should report that error and exit.
return Futures.wait([
client.get(server.resolve("/packages/versions/new.json")),
_filesToPublish.transform((files) {
@@ -103,13 +94,18 @@ class LishCommand extends PubCommand {
}
throw errorMap['error']['message'];
}
+ } else if (e is oauth2.ExpirationException) {
+ printError("Pub's authorization to upload packages has expired and "
+ "can't be automatically refreshed.");
+ return onRun();
+ } else if (e is oauth2.AuthorizationException) {
+ var message = "OAuth2 authorization failed";
+ if (e.description != null) message = "$message (${e.description})";
+ printError("$message.");
+ return oauth2.clearCredentials(cache).chain((_) => onRun());
+ } else {
+ throw e;
}
-
- if (e is! oauth2.ExpirationException) throw e;
-
- printError("Pub's authorization to upload packages has expired and can't "
- "be automatically refreshed.");
- return onRun();
});
}
« no previous file with comments | « no previous file | utils/pub/io.dart » ('j') | utils/tests/pub/pub_lish_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698