Bug 1273343 - make more log noise on resource exceptions and errors. r=tcsc
MozReview-Commit-ID: 6pa8MvoNnwb
--- a/services/sync/modules/resource.js
+++ b/services/sync/modules/resource.js
@@ -301,16 +301,19 @@ AsyncResource.prototype = {
}
let ret = new String(data);
ret.url = channel.URI.spec;
ret.status = status;
ret.success = success;
ret.headers = headers;
+ if (!success) {
+ this._log.warn(`${action} request to ${ret.url} failed with status ${status}`);
+ }
// Make a lazy getter to convert the json response into an object.
// Note that this can cause a parse error to be thrown far away from the
// actual fetch, so be warned!
XPCOMUtils.defineLazyGetter(ret, "obj", function() {
try {
return JSON.parse(ret);
} catch (ex) {
this._log.warn("Got exception parsing response body", ex);
@@ -380,16 +383,18 @@ Resource.prototype = {
// The channel listener might get a failure code
try {
this._doRequest(action, data, callback);
return Async.waitForSyncCallback(cb);
} catch (ex) {
if (Async.isShutdownException(ex)) {
throw ex;
}
+ this._log.warn("${action} request to ${url} failed: ${ex}",
+ { action, url: this.uri.spec, ex });
// Combine the channel stack with this request stack. Need to create
// a new error object for that.
let error = Error(ex.message);
error.result = ex.result;
let chanStack = [];
if (ex.stack)
chanStack = ex.stack.trim().split(/\n/).slice(1);
let requestStack = error.stack.split(/\n/).slice(1);
--- a/services/sync/tests/unit/test_resource.js
+++ b/services/sync/tests/unit/test_resource.js
@@ -437,16 +437,18 @@ function run_test() {
content = res18.get();
} catch (ex) {
error = ex;
}
// It throws and logs.
do_check_eq(error.result, Cr.NS_ERROR_MALFORMED_URI);
do_check_eq(error, "Error: NS_ERROR_MALFORMED_URI");
+ // Note the strings haven't been formatted yet, but that's OK for this test.
+ do_check_eq(warnings.pop(), "${action} request to ${url} failed: ${ex}");
do_check_eq(warnings.pop(),
"Got exception calling onProgress handler during fetch of " +
server.baseURI + "/json");
// And this is what happens if JS throws an exception.
res18 = new Resource(server.baseURI + "/json");
onProgress = function(rec) {
throw "BOO!";
@@ -460,16 +462,17 @@ function run_test() {
content = res18.get();
} catch (ex) {
error = ex;
}
// It throws and logs.
do_check_eq(error.result, Cr.NS_ERROR_XPC_JS_THREW_STRING);
do_check_eq(error, "Error: NS_ERROR_XPC_JS_THREW_STRING");
+ do_check_eq(warnings.pop(), "${action} request to ${url} failed: ${ex}");
do_check_eq(warnings.pop(),
"Got exception calling onProgress handler during fetch of " +
server.baseURI + "/json");
_("Ensure channel timeouts are thrown appropriately.");
let res19 = new Resource(server.baseURI + "/json");
res19.ABORT_TIMEOUT = 0;