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 /** | 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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 // consumeInputStream() (but this one propagates errors). Merge them when | 318 // consumeInputStream() (but this one propagates errors). Merge them when |
319 // #3657 is fixed. | 319 // #3657 is fixed. |
320 uri = _getUri(uri); | 320 uri = _getUri(uri); |
321 | 321 |
322 var completer = new Completer<String>(); | 322 var completer = new Completer<String>(); |
323 var client = new HttpClient(); | 323 var client = new HttpClient(); |
324 var connection = client.getUrl(uri); | 324 var connection = client.getUrl(uri); |
325 | 325 |
326 connection.onError = (e) { | 326 connection.onError = (e) { |
327 // Show a friendly error if the URL couldn't be resolved. | 327 // Show a friendly error if the URL couldn't be resolved. |
328 if (e is SocketIOException && e.osError.errorCode == 8) { | 328 if (e is SocketIOException && |
| 329 (e.osError.errorCode == 8 || e.osError.errorCode == -2)) { |
329 e = 'Could not resolve URL "${uri.origin}".'; | 330 e = 'Could not resolve URL "${uri.origin}".'; |
330 } | 331 } |
331 | 332 |
332 client.shutdown(); | 333 client.shutdown(); |
333 completer.completeException(e); | 334 completer.completeException(e); |
334 }; | 335 }; |
335 | 336 |
336 connection.onResponse = (response) { | 337 connection.onResponse = (response) { |
337 if (response.statusCode >= 400) { | 338 if (response.statusCode >= 400) { |
338 client.shutdown(); | 339 client.shutdown(); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 return new Directory(entry); | 549 return new Directory(entry); |
549 } | 550 } |
550 | 551 |
551 /** | 552 /** |
552 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 553 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
553 */ | 554 */ |
554 Uri _getUri(uri) { | 555 Uri _getUri(uri) { |
555 if (uri is Uri) return uri; | 556 if (uri is Uri) return uri; |
556 return new Uri.fromString(uri); | 557 return new Uri.fromString(uri); |
557 } | 558 } |
OLD | NEW |