Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor getCacheCallback to directly use parent promise's resolve an… #271

Merged
merged 3 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
## Change log
### Version: 3.24.1
#### Date: January-27-2025
##### Fix:
- Added HTTP error codes in the findOne method

### Version: 3.24.0
#### Date: January-27-2025
##### Enhancement:
- updateasseturl for handling jrte within blocks
- version bumps
- Fixed testcases

### Version: 3.23.0
#### Date: December-05-2024
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "contentstack",
"version": "3.24.0",
"version": "3.24.1",
"description": "Contentstack Javascript SDK",
"homepage": "https://www.contentstack.com/",
"author": {
Expand Down
35 changes: 19 additions & 16 deletions src/core/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,19 +252,20 @@ export function sendRequest(queryObject, options) {
}
}

let getCacheCallback = function() {
let getCacheCallback = function(resolve, reject) {
return function(err, entries) {
return new Promise(function(resolve, reject) {
try {
if (err) reject(err);
if (!tojson) entries = resultWrapper(entries);
resolve(spreadResult(entries));
} catch (e) {
reject(e)
try {
if (err) {
return reject(err); // Propagate the error to the parent promise
}
});
}
}
if (!tojson) entries = resultWrapper(entries);
resolve(spreadResult(entries)); // Propagate the result to the parent promise
} catch (e) {
reject(e); // Handle any synchronous errors
}
};
};


let callback = function(continueFlag, resolve, reject) {
if (continueFlag) {
Expand All @@ -291,7 +292,7 @@ export function sendRequest(queryObject, options) {
if (err || !_data || (_data.entries.length === 0 && _data.assets.length === 0)) {
return reject({ error_code: 141, error_message: 'The requested entry doesn\'t exist.' });
}
getCacheCallback()(err, _data);
getCacheCallback(resolve, reject)(err, _data);
});
return
} else {
Expand Down Expand Up @@ -338,12 +339,14 @@ export function sendRequest(queryObject, options) {
}
}.bind(self))
.catch(function(error) {
if (cachePolicy === 2 && self.provider !== null) {
self.provider.get(hashQuery, getCacheCallback());
} else {
return reject(error);
if(error){
reject(error);
}
else if (cachePolicy === 2 && self.provider !== null) {
self.provider.get(hashQuery, getCacheCallback(resolve, reject));
}
});

}
}
switch (cachePolicy) {
Expand Down
Loading