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

Side by Side Diff: utils/pub/io.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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * Helper functionality to make working with IO easier. 6 * Helper functionality to make working with IO easier.
7 */ 7 */
8 library io; 8 library io;
9 9
10 import 'dart:io'; 10 import 'dart:io';
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 var stackTrace; 510 var stackTrace;
511 try { 511 try {
512 throw null; 512 throw null;
513 } catch (_, localStackTrace) { 513 } catch (_, localStackTrace) {
514 stackTrace = localStackTrace; 514 stackTrace = localStackTrace;
515 } 515 }
516 516
517 // TODO(nweiz): Ideally the timeout would extend to reading from the 517 // TODO(nweiz): Ideally the timeout would extend to reading from the
518 // response input stream, but until issue 3657 is fixed that's not feasible. 518 // response input stream, but until issue 3657 is fixed that's not feasible.
519 return timeout(_inner.send(request).chain((streamedResponse) { 519 return timeout(_inner.send(request).chain((streamedResponse) {
520 if (streamedResponse.statusCode < 400) { 520 var status = streamedResponse.statusCode;
521 // 401 responses should be handled by the OAuth2 client. It's very
522 // unlikely that they'll be returned by non-OAuth2 requests.
523 if (status < 400 || status == 401) {
521 return new Future.immediate(streamedResponse); 524 return new Future.immediate(streamedResponse);
522 } 525 }
523 526
524 return http.Response.fromStream(streamedResponse).transform((response) { 527 return http.Response.fromStream(streamedResponse).transform((response) {
525 throw new PubHttpException(response); 528 throw new PubHttpException(response);
526 }); 529 });
527 }).transformException((e) { 530 }).transformException((e) {
528 if (e is SocketIOException && 531 if (e is SocketIOException &&
529 e.osError != null && 532 e.osError != null &&
530 (e.osError.errorCode == 8 || 533 (e.osError.errorCode == 8 ||
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 } 947 }
945 948
946 /** 949 /**
947 * Exception thrown when an HTTP operation fails. 950 * Exception thrown when an HTTP operation fails.
948 */ 951 */
949 class PubHttpException implements Exception { 952 class PubHttpException implements Exception {
950 final http.Response response; 953 final http.Response response;
951 954
952 const PubHttpException(this.response); 955 const PubHttpException(this.response);
953 956
954 String toString() => 'HTTP error ${response.statusCode}: ${response.reason}'; 957 String toString() => 'HTTP error ${response.statusCode}: '
958 '${response.reasonPhrase}';
955 } 959 }
956 960
957 /** 961 /**
958 * Exception thrown when an operation times out. 962 * Exception thrown when an operation times out.
959 */ 963 */
960 class TimeoutException implements Exception { 964 class TimeoutException implements Exception {
961 final String message; 965 final String message;
962 966
963 const TimeoutException(this.message); 967 const TimeoutException(this.message);
964 968
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 return new Directory(entry); 1019 return new Directory(entry);
1016 } 1020 }
1017 1021
1018 /** 1022 /**
1019 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. 1023 * Gets a [Uri] for [uri], which can either already be one, or be a [String].
1020 */ 1024 */
1021 Uri _getUri(uri) { 1025 Uri _getUri(uri) {
1022 if (uri is Uri) return uri; 1026 if (uri is Uri) return uri;
1023 return new Uri.fromString(uri); 1027 return new Uri.fromString(uri);
1024 } 1028 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698