Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}