Chromium Code Reviews| Index: recipes/dart_io/pkg_http/bin/handling_an_httprequest_error.dart |
| diff --git a/recipes/dart_io/pkg_http/bin/handling_an_httprequest_error.dart b/recipes/dart_io/pkg_http/bin/handling_an_httprequest_error.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..83ebc5aca38993b6a737992b3dfbfdcfdd7a3d56 |
| --- /dev/null |
| +++ b/recipes/dart_io/pkg_http/bin/handling_an_httprequest_error.dart |
| @@ -0,0 +1,18 @@ |
| +import 'dart:io' show SocketException; |
| +import 'package:http/http.dart' as http; |
| + |
| +handleSuccess(http.Response response) { |
| + print('something went wrong'); |
| + print(response.body); |
| +} |
| + |
| +handleFailure(SocketException e) { |
|
Anders Johnsen
2013/12/06 11:53:28
Don't expect SocketException. In theory, it could
shailentuli
2013/12/06 18:16:29
Done.
|
| + print(e.message); |
| + print('A ${e.runtimeType} was raised'); |
| +} |
| + |
| +void main() { |
| + http.get("http://some_bogus_website.org") |
| + .then(handleSuccess) |
| + .catchError(handleFailure); |
| +} |