How to use the @wireapp/store-engine/dist/commonjs/engine/error/.RecordNotFoundError function in @wireapp/store-engine

To help you get started, we’ve selected a few @wireapp/store-engine examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wireapp / wire-web-packages / packages / store-engine-fs / src / index.ts View on Github external
async read(tableName: string, primaryKey: string): Promise {
    const file = await this.resolvePath(tableName, primaryKey);
    let data: any;

    try {
      data = await fs.readFile(file, {encoding: 'utf8', flag: 'r'});
    } catch (error) {
      if (error.code === 'ENOENT') {
        const message = `Record "${primaryKey}" in "${tableName}" could not be found.`;
        throw new RecordNotFoundError(message);
      }
      throw error;
    }

    try {
      data = JSON.parse(data);
    } catch (error) {
      // No JSON found but that's okay
    }

    return data;
  }