Error Handling

// Any API request method behave the same way

// Using callbacks (NodeJS or Web Browser)
kuzzle.checkToken(token, function (err, res) {
  if (err) {
    console.error(err.status, ': ', err.message);
    return;
  }
});

// Using promises (NodeJS only)
kuzzle.checkTokenPromise(token)
  .then(res => {
    // ...
  })
  .catch(err => {
    console.error(err.status, ': ', err.message);
    return Promise.reject(err);
  });
kuzzle.checkToken("some jwt token", new ResponseListener<TokenValidity>() {
  @Override
  public void onSuccess(TokenValidity tokenInfo) {
    if (tokenInfo.isValid()) {
      // tokenInfo.getExpiresAt() returns the expiration timestamp
    }
    else {
      // tokenInfo.getState() returns the invalidity reason
    }
  }

  @Override
  public void onError(JSONObject error) {
    System.err.println(error.getInt('status') + ': ' + error.getString('message'));
  }
});
<?php

try {
  $result = $kuzzle->checkToken('some jwt token');
}
catch (ErrorException $e) {
  var_dump($e->status . ': ' . $e->message);
}

All methods that accept a callback as an argument can return an error. The error can be generated directly by the SDK, or by Kuzzle and included in the response to a request.

All errors generated by Kuzzle contain the following properties:

  • message: the error message
  • status: an error code following the HTTP standard