How to use the @wireapp/store-engine/dist/commonjs/engine/error/.RecordAlreadyExistsError 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
entity = JSON.stringify(entity);
        } catch (error) {
          entity = entity.toString();
        }
      }

      try {
        await fs.writeFile(filePath, entity, {flag: 'wx'});
        return primaryKey;
      } catch (error) {
        if (error.code === 'ENOENT') {
          await fs.outputFile(filePath, entity);
          return primaryKey;
        } else if (error.code === 'EEXIST') {
          const message = `Record "${primaryKey}" already exists in "${tableName}". You need to delete the record first if you want to overwrite it.`;
          throw new RecordAlreadyExistsError(message);
        }
        throw error;
      }
    } else {
      const message = `Record "${primaryKey}" cannot be saved in "${tableName}" because it's "undefined" or "null".`;
      throw new RecordTypeError(message);
    }
  }