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

Unified Diff: utils/pub/oauth2.dart

Issue 11830017: Fix ALL the pub tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months 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 900abf6226024053a22c4e8fa288072dd5d6b234..5ce0cefa60e7acb088d20e7dcf7bafd2a4453715 100644
--- a/utils/pub/oauth2.dart
+++ b/utils/pub/oauth2.dart
@@ -69,23 +69,13 @@ Future clearCredentials(SystemCache cache) {
Future withClient(SystemCache cache, Future fn(Client client)) {
return _getClient(cache).then((client) {
var completer = new Completer();
- var future = fn(client);
- future.whenComplete(() {
- try {
- client.close();
- // Be sure to save the credentials even when an error happens. Also be
- // sure to pipe the exception from `future` to `completer`.
- chainToCompleter(
- _saveCredentials(cache, client.credentials).then((_) => future),
- completer);
- } catch (e, stackTrace) {
- // whenComplete will drop exceptions on the floor. We want to ensure
- // that any programming errors here don't go un-noticed. See issue 4127.
- completer.completeError(e, stackTrace);
- }
+ return asyncWhenComplete(fn(client), () {
+ client.close();
+ // Be sure to save the credentials even when an error happens.
+ return _saveCredentials(cache, client.credentials);
});
- return completer.future;
- }).catchError((e) {
+ }).catchError((asyncError) {
+ var e = getRealError(asyncError);
if (e is ExpirationException) {
log.error("Pub's authorization to upload packages has expired and "
"can't be automatically refreshed.");
@@ -96,7 +86,7 @@ Future withClient(SystemCache cache, Future fn(Client client)) {
log.error("$message.");
return clearCredentials(cache).then((_) => withClient(cache, fn));
} else {
- throw e;
+ throw asyncError;
}
});
}

Powered by Google App Engine
This is Rietveld 408576698