Skip to content

Commit ec892c6

Browse files
Include HTTP error codes in the findOne method
1 parent d9a6df0 commit ec892c6

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Change log
22

3+
### Version: 3.23.0
4+
#### Date: December-05-2024
5+
##### Enhancement:
6+
- Added HTTP error codes in the findOne method
7+
38
### Version: 3.22.2
49
#### Date: November-18-2024
510
##### Fix:

package-lock.json

Lines changed: 2 additions & 2 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.22.2",
3+
"version": "3.23.0",
44
"description": "Contentstack Javascript SDK",
55
"homepage": "https://www.contentstack.com/",
66
"author": {

src/core/modules/query.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,6 @@ export default class Query extends Entry {
828828
host = this.config.protocol + "://" + this.live_preview.host + '/' + this.config.version
829829
}
830830
const url = getRequestUrl(this.type, this.config, this.content_type_uid, host)
831-
832831
this.singleEntry = true;
833832
this._query.limit = 1;
834833
this.requestParams = {
@@ -840,8 +839,17 @@ export default class Query extends Entry {
840839
query: this._query
841840
}
842841
};
843-
var options = Utils.mergeDeep({}, this.fetchOptions);
844-
return Utils.sendRequest(Utils.mergeDeep({}, this), options);
842+
const options = Utils.mergeDeep({}, this.fetchOptions);
843+
return Utils.sendRequest(Utils.mergeDeep({}, this), options).catch(error => {
844+
// Add HTTP status code to the error object if it exists
845+
if (error.status) {
846+
return Promise.reject({
847+
...error,
848+
http_code: error.status, // Adding the HTTP status code explicitly
849+
http_message: error.statusText || 'An error occurred'
850+
});
851+
}
852+
return Promise.reject(error); // Fallback for other errors
853+
});
845854
}
846-
847855
}

0 commit comments

Comments
 (0)