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 |
---|---|---|
kuzzleStack | string | Kuzzle stacktrace (only in development mode) |
status | number | Error status code |
id | string | Error unique identifier |
code | string | Error unique code |
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 === 412) {
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 === 412) {
console.log(error.message);
console.log('Try with another name!');
}
}
Edit this page on Github(opens new window)