Skip to content

Commit

Permalink
fix(thenable): Make sure the fetch function is a promise returning va…
Browse files Browse the repository at this point in the history
…lues, log error if not
  • Loading branch information
Luc Merceron committed Sep 19, 2017
1 parent cbd97de commit be18443
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/referenceFetcher.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'babel-polyfill'
// import 'babel-polyfill'
import { isArray, isObject } from 'lodash'
import warning from './util/warning'

Expand Down Expand Up @@ -88,12 +88,15 @@ fetchSubRef = (ref, parentObject) => {
// Else we need to wait for each request response to go further
else return Promise.all(idsToFetch.map(fetch))
}
fetchEnhancedCall().then(values => {
Promise.resolve(fetchEnhancedCall()).then(values => {
// If the fetch did not returned values, warn the client
if (!values) warning(`the fetch for entity ${entity} returned no values`)

// Register the new objects in our cache for future use
if (values) values.forEach(value => registerNewEntity(entity, value.id, value))

// Continue with underneath references with our fetched and cached values
if (subRefs) fetchSubRefs(subRefs, [...values, ...alreadyFetched])
if (values && subRefs) fetchSubRefs(subRefs, [...values, ...alreadyFetched])
}, reason => {
warning(`the fetch for entity ${entity} returned an error: ${reason}`)
})
Expand Down

0 comments on commit be18443

Please sign in to comment.