diff --git a/addon/adapters/rest.js b/addon/adapters/rest.js index ab0ea8766d9..6bcc3db9fc3 100644 --- a/addon/adapters/rest.js +++ b/addon/adapters/rest.js @@ -992,9 +992,6 @@ const RESTAdapter = Adapter.extend(BuildURLMixin, { if (get(this, 'useFetch')) { return this._fetchRequest(hash) - .catch(() => { - heimdall.stop(token); - }) .then(response => { heimdall.stop(token); @@ -1009,6 +1006,9 @@ const RESTAdapter = Adapter.extend(BuildURLMixin, { } else { throw fetchErrorHandler(adapter, payload, response, null, requestData); } + }) + .catch(() => { + heimdall.stop(token); }); } @@ -1054,7 +1054,7 @@ const RESTAdapter = Adapter.extend(BuildURLMixin, { }, _fetchRequest(options) { - fetch(options.url, options) + return fetch(options.url, options) .then(response => { if (response.ok) { options.success(response); diff --git a/tests/unit/adapters/rest-adapter/fetch-test.js b/tests/unit/adapters/rest-adapter/fetch-test.js index 4e11f58772e..475f2d84976 100644 --- a/tests/unit/adapters/rest-adapter/fetch-test.js +++ b/tests/unit/adapters/rest-adapter/fetch-test.js @@ -133,3 +133,24 @@ test('ajaxOptions() empty data', function(assert) { url: 'example.com', }); }); + +test('_fetchRequest() returns a promise', function(assert) { + console.log('DS.RESTAdapter', adapter); + let noop = function(){}; + + return run(() => { + let fetchPlacePromise = adapter._fetchRequest({ + url: '/places/1', + success: noop, + error: noop, + }); + + assert.equal( + typeof fetchPlacePromise.then, + 'function', + '_fetchRequest does not return a promise' + ); + + return fetchPlacePromise; + }); +});