Permalink
Browse files

Catch exceptions from NetUtil.asyncFetch.

  • Loading branch information...
1 parent 7cefe8c commit 55522ecc50a4a7e830d4ac3575a47775161f1f1c @Mossop committed Dec 19, 2012
Showing with 15 additions and 10 deletions.
  1. +15 −10 lib/sdk/net/url.js
View
25 lib/sdk/net/url.js
@@ -40,16 +40,21 @@ function readAsync(uri, charset) {
let { promise, resolve, reject } = defer();
- NetUtil.asyncFetch(channel, function (stream, result) {
- if (components.isSuccessCode(result)) {
- let count = stream.available();
- let data = NetUtil.readInputStreamToString(stream, count, { charset : charset });
-
- resolve(data);
- } else {
- reject("Failed to read: '" + uri + "' (Error Code: " + result + ")");
- }
- });
+ try {
+ NetUtil.asyncFetch(channel, function (stream, result) {
+ if (components.isSuccessCode(result)) {
+ let count = stream.available();
+ let data = NetUtil.readInputStreamToString(stream, count, { charset : charset });
+
+ resolve(data);
+ } else {
+ reject("Failed to read: '" + uri + "' (Error Code: " + result + ")");
+ }
+ });
+ }
+ catch (e) {
+ reject("Failed to read: '" + uri + "' (Error: " + e.message + ")");
+ }
return promise;
}

0 comments on commit 55522ec

Please sign in to comment.