Skip to content

Commit

Permalink
[BUGFIX #5918] Fix promise not being returned
Browse files Browse the repository at this point in the history
  • Loading branch information
mschinis authored and runspired committed Mar 21, 2019
1 parent dde10f7 commit 4fdde1e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 4 additions & 4 deletions addon/adapters/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -1009,6 +1006,9 @@ const RESTAdapter = Adapter.extend(BuildURLMixin, {
} else {
throw fetchErrorHandler(adapter, payload, response, null, requestData);
}
})
.catch(() => {
heimdall.stop(token);
});
}

Expand Down Expand Up @@ -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);
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/adapters/rest-adapter/fetch-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});

0 comments on commit 4fdde1e

Please sign in to comment.