SDK
SDK Javascript v7.x
2

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 #

Copied to clipboard!
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 #

Copied to clipboard!
try {
  await kuzzle.index.create('nyc-open-data');
} catch (error) {
  if (error.status === 412) {
    console.log(error.message);
    console.log('Try with another name!');
  }
}