Error Handling #
All SDK methods return a promise, that can be rejected with a KuzzleError
value in case of failure.
KuzzleError objects inherit the standard Error
object, and add the following properties to it:
Property | Type | Description |
---|---|---|
status | number | Status following HTTP Standards |
stack | string | Error stacktrace (Only in development mode) |
You can find a detailed list of possible errors messages and statuses in the documentation API.
Example with a promise chain #
kuzzle.index.create('nyc-open-data')
.then(() => 'do something')
.catch(error => {
if (error.status === 400) {
console.log(error.message);
console.log('Try with another name!');
}
});
Example with async/await #
try {
await kuzzle.index.create('nyc-open-data');
} catch (error) {
if (error.status === 400) {
console.log(error.message);
console.log('Try with another name!');
}
}
Edit this page on Github(opens new window)