| OLD | NEW |
| 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 /// Helpers for dealing with HTTP. | 5 /// Helpers for dealing with HTTP. |
| 6 library pub.http; | 6 library pub.http; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 import 'dart:json' as json; | 10 import 'dart:json' as json; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 | 53 |
| 54 return http.Response.fromStream(streamedResponse).then((response) { | 54 return http.Response.fromStream(streamedResponse).then((response) { |
| 55 throw new PubHttpException(response); | 55 throw new PubHttpException(response); |
| 56 }); | 56 }); |
| 57 }).catchError((asyncError) { | 57 }).catchError((asyncError) { |
| 58 if (asyncError.error is SocketIOException && | 58 if (asyncError.error is SocketIOException && |
| 59 asyncError.error.osError != null) { | 59 asyncError.error.osError != null) { |
| 60 if (asyncError.error.osError.errorCode == 8 || | 60 if (asyncError.error.osError.errorCode == 8 || |
| 61 asyncError.error.osError.errorCode == -2 || | 61 asyncError.error.osError.errorCode == -2 || |
| 62 asyncError.error.osError.errorCode == -5 || | 62 asyncError.error.osError.errorCode == -5 || |
| 63 asyncError.error.osError.errorCode == 11001 || |
| 63 asyncError.error.osError.errorCode == 11004) { | 64 asyncError.error.osError.errorCode == 11004) { |
| 64 throw 'Could not resolve URL "${request.url.origin}".'; | 65 throw 'Could not resolve URL "${request.url.origin}".'; |
| 65 } else if (asyncError.error.osError.errorCode == -12276) { | 66 } else if (asyncError.error.osError.errorCode == -12276) { |
| 66 throw 'Unable to validate SSL certificate for ' | 67 throw 'Unable to validate SSL certificate for ' |
| 67 '"${request.url.origin}".'; | 68 '"${request.url.origin}".'; |
| 68 } | 69 } |
| 69 } | 70 } |
| 70 throw asyncError; | 71 throw asyncError; |
| 71 }), HTTP_TIMEOUT, 'fetching URL "${request.url}"'); | 72 }), HTTP_TIMEOUT, 'fetching URL "${request.url}"'); |
| 72 } | 73 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 127 |
| 127 /// Exception thrown when an HTTP operation fails. | 128 /// Exception thrown when an HTTP operation fails. |
| 128 class PubHttpException implements Exception { | 129 class PubHttpException implements Exception { |
| 129 final http.Response response; | 130 final http.Response response; |
| 130 | 131 |
| 131 const PubHttpException(this.response); | 132 const PubHttpException(this.response); |
| 132 | 133 |
| 133 String toString() => 'HTTP error ${response.statusCode}: ' | 134 String toString() => 'HTTP error ${response.statusCode}: ' |
| 134 '${response.reasonPhrase}'; | 135 '${response.reasonPhrase}'; |
| 135 } | 136 } |
| OLD | NEW |