formatESError(error) {
    if (error instanceof KuzzleError) {
      return error;
    }

    global.kuzzle.emit("services:storage:error", {
      message: `Elasticsearch Client error: ${error.message}`,
      // /!\ not all ES error classes have a "meta" property
      meta: error.meta || null,
      stack: error.stack,
    });

    if (error instanceof es.errors.NoLivingConnectionsError) {
      throw kerror.get("not_connected");
    }
    const message = _.get(error, "meta.body.error.reason", error.message);

    // Try to match a known elasticsearch error
    for (const betterError of errorMessagesMapping) {
      const matches = message.match(betterError.regex);

      if (matches) {
        return kerror.get(
          betterError.subcode,
          ...betterError.getPlaceholders(error, matches),
        );
      }
    }

    // Try to match using error codes
    if (error.meta) {
      switch (error.meta.statusCode) {
        case 400:
          return this._handleBadRequestError(error, message);
        case 404:
          return this._handleNotFoundError(error, message);
        case 409:
          return this._handleConflictError(error, message);
        default:
          break;
      }
    }

    return this._handleUnknownError(error, message);
  }
Transforms raw ES errors into a normalized Kuzzle version

@param {Error} error
@returns {KuzzleError}