Skip to content

Commit 4ef7d07

Browse files
authored
Merge pull request #42 from contentstack/error_handling
Unhandled Promise rejection issue resolve
2 parents 41f6a3d + 280971b commit 4ef7d07

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
2+
### Version: 3.12.1
3+
#### Date: Jan-22-2021
4+
5+
##### Bug fix:
6+
- Fixed Unhandled promise rejection on HTML response body.
17
### Version: 3.12.0
2-
#### Date: Desc-05-2020
8+
#### Date: Dec-05-2020
39

410
##### New Features:
511
- [Entry] - Publish fallback method added

package-lock.json

Lines changed: 14 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "contentstack",
3-
"version": "3.12.0",
3+
"version": "3.12.1",
44
"description": "Contentstack Javascript SDK",
55
"homepage": "https://www.contentstack.com/",
66
"author": {

src/core/lib/request.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ function wait(retryDelay) {
5757
setTimeout(resolve, retryDelay)
5858
});
5959
}
60-
60+
async function safeParseJSON(response) {
61+
const body = await response.text();
62+
}
6163
function fetchRetry(url, headers, retryDelay = 300, retryLimit = 5, fetchOptions, resolve, reject) {
6264
var option = Object.assign({
6365
method: 'GET',
@@ -87,7 +89,7 @@ function fetchRetry(url, headers, retryDelay = 300, retryLimit = 5, fetchOptions
8789
}
8890
}
8991
fetch(url, option)
90-
.then(function(response) {
92+
.then(function(response) {
9193
let data = response.json();
9294
if (response.ok && response.status === 200) {
9395
resolve(data);
@@ -98,6 +100,8 @@ function fetchRetry(url, headers, retryDelay = 300, retryLimit = 5, fetchOptions
98100
} else {
99101
reject(json)
100102
}
103+
}).catch(() => {
104+
reject({status: response.status, statusText: response.statusText})
101105
});
102106
}
103107
}).catch((error) => {

0 commit comments

Comments
 (0)