Skip to content

Commit

Permalink
fix(bundle): fetch API isn't always an instance of Response (#744)
Browse files Browse the repository at this point in the history
- the output of the Fetch API Promise isn't always an `instanceof Response`, the better way of validating the Fetch resolved output is to check its status to be between 200-300 and also make sure that it has the `.json()` type to be a function
  • Loading branch information
ghiscoding committed Aug 13, 2022
1 parent b702596 commit 72a6f24
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1176,15 +1176,15 @@ export class SlickVanillaGridBundle {
collectionAsync.then((response: any | any[]) => {
if (Array.isArray(response)) {
this.updateEditorCollection(column, response); // from Promise
} else if (response instanceof Response && typeof response.json === 'function') {
} else if (response?.status >= 200 && response.status < 300 && typeof response.json === 'function') {
if (response.bodyUsed) {
console.warn(`[SlickGrid-Universal] The response body passed to collectionAsync was already read.`
+ `Either pass the dataset from the Response or clone the response first using response.clone()`);
} else {
// from Fetch
(response as Response).json().then(data => this.updateEditorCollection(column, data));
}
} else if (response && response['content']) {
} else if (response?.content) {
this.updateEditorCollection(column, response['content']); // from http-client
}
});
Expand Down

0 comments on commit 72a6f24

Please sign in to comment.