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 library hosted_source; | 5 library hosted_source; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io' as io; | 8 import 'dart:io' as io; |
9 import 'dart:json' as json; | 9 import 'dart:json' as json; |
10 import 'dart:uri'; | 10 import 'dart:uri'; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 /// given name from the default host, while a map with keys "name" and "url" | 112 /// given name from the default host, while a map with keys "name" and "url" |
113 /// refers to a package with the given name from the host at the given URL. | 113 /// refers to a package with the given name from the host at the given URL. |
114 void validateDescription(description, {bool fromLockFile: false}) { | 114 void validateDescription(description, {bool fromLockFile: false}) { |
115 _parseDescription(description); | 115 _parseDescription(description); |
116 } | 116 } |
117 | 117 |
118 /// When an error occurs trying to read something about [package] from [url], | 118 /// When an error occurs trying to read something about [package] from [url], |
119 /// this tries to translate into a more user friendly error message. Always | 119 /// this tries to translate into a more user friendly error message. Always |
120 /// throws an error, either the original one or a better one. | 120 /// throws an error, either the original one or a better one. |
121 void _throwFriendlyError(ex, package, url) { | 121 void _throwFriendlyError(ex, package, url) { |
| 122 ex = getRealError(ex); |
| 123 |
122 if (ex is PubHttpException && ex.response.statusCode == 404) { | 124 if (ex is PubHttpException && ex.response.statusCode == 404) { |
123 throw 'Could not find package "$package" at $url.'; | 125 throw 'Could not find package "$package" at $url.'; |
124 } | 126 } |
125 | 127 |
126 if (ex is TimeoutException) { | 128 if (ex is TimeoutException) { |
127 throw 'Timed out trying to find package "$package" at $url.'; | 129 throw 'Timed out trying to find package "$package" at $url.'; |
128 } | 130 } |
129 | 131 |
130 if (ex is io.SocketIOException) { | 132 if (ex is io.SocketIOException) { |
131 throw 'Got socket error trying to find package "$package" at $url.\n' | 133 throw 'Got socket error trying to find package "$package" at $url.\n' |
(...skipping 25 matching lines...) Expand all Loading... |
157 | 159 |
158 var name = description["name"]; | 160 var name = description["name"]; |
159 if (name is! String) { | 161 if (name is! String) { |
160 throw new FormatException("The 'name' key must have a string value."); | 162 throw new FormatException("The 'name' key must have a string value."); |
161 } | 163 } |
162 | 164 |
163 var url = description.containsKey("url") ? description["url"] : defaultUrl; | 165 var url = description.containsKey("url") ? description["url"] : defaultUrl; |
164 return new Pair<String, String>(name, url); | 166 return new Pair<String, String>(name, url); |
165 } | 167 } |
166 } | 168 } |
OLD | NEW |