From d9fb744b2123f39ffe15123ce367e8d3e0fa330a Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Mon, 8 Feb 2016 11:31:24 +0100 Subject: [PATCH 1/2] Include statusText in error object --- shared/fetcher.js | 1 + shared/syncer.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/shared/fetcher.js b/shared/fetcher.js index 4ff6adf3..26d54c8b 100644 --- a/shared/fetcher.js +++ b/shared/fetcher.js @@ -187,6 +187,7 @@ Fetcher.prototype.fetchFromApi = function(spec, options, callback) { respOutput = JSON.stringify(resp); err = new Error("ERROR fetching model '" + fetcher.modelUtils.modelName(model.constructor) + "' with options '" + JSON.stringify(options) + "'. Response: " + respOutput); err.status = resp.status; + err.statusText = resp.statusText; err.body = body; callback(err); } diff --git a/shared/syncer.js b/shared/syncer.js index 00d2800c..8a45d187 100644 --- a/shared/syncer.js +++ b/shared/syncer.js @@ -48,7 +48,8 @@ function clientSync(method, model, options) { } resp = { body: body, - status: xhr.status + status: xhr.status, + statusText: xhr.statusText }; error(resp); } From f0a4aeaa3a2435db95c557e014f46af560cf7814 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Mon, 8 Feb 2016 13:21:23 +0100 Subject: [PATCH 2/2] Updated tests with statusText --- test/shared/syncer.test.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/shared/syncer.test.js b/test/shared/syncer.test.js index bfb8d68f..8d7f148f 100644 --- a/test/shared/syncer.test.js +++ b/test/shared/syncer.test.js @@ -255,6 +255,7 @@ describe('syncer', function() { fakeXhr = { responseText: '{"foo": "bar"}', status: 418, + statusText: 0, getResponseHeader: sinon.stub() }; options.error = syncErrorHandler; @@ -264,7 +265,8 @@ describe('syncer', function() { it('should call the original error handler with status and body', function () { var expectedResponse = { body: fakeXhr.responseText, - status: fakeXhr.status + status: fakeXhr.status, + statusText: fakeXhr.statusText }; syncer.clientSync.call(model, 'read', model, options); @@ -276,7 +278,8 @@ describe('syncer', function() { it('should parse the payload if content-type is "application/json"', function () { var expectedResponse = { body: JSON.parse(fakeXhr.responseText), - status: fakeXhr.status + status: fakeXhr.status, + statusText: fakeXhr.statusText, }; fakeXhr.getResponseHeader.withArgs('content-type').returns('application/json'); @@ -334,6 +337,7 @@ describe('syncer', function() { fakeXhr = { responseText: '{"foo": "bar"}', status: 418, + statusText: 0, getResponseHeader: sinon.stub() }; options.error = syncErrorHandler; @@ -343,7 +347,8 @@ describe('syncer', function() { it('should call the original error handler with status and body', function () { var expectedResponse = { body: fakeXhr.responseText, - status: fakeXhr.status + status: fakeXhr.status, + statusText: fakeXhr.statusText }; syncer.clientSync.call(model, 'read', model, options); @@ -355,7 +360,8 @@ describe('syncer', function() { it('should parse the payload if content-type is "application/json"', function () { var expectedResponse = { body: JSON.parse(fakeXhr.responseText), - status: fakeXhr.status + status: fakeXhr.status, + statusText: fakeXhr.statusText }; fakeXhr.getResponseHeader.withArgs('content-type').returns('application/json');