diff --git a/lib/BankLetter.js b/lib/BankLetter.js index 1a98282..eb732ad 100644 --- a/lib/BankLetter.js +++ b/lib/BankLetter.js @@ -24,6 +24,12 @@ const registerHelpers = () => { return digest.toUpperCase().match(/.{1,2}/g).join(' '); }); }; + +const writeFile = (file, content) => new Promise((resolve, reject) => fs.writeFile(file, content, (err, result) => { + if (err) + return reject(err); + return resolve(result); +})); module.exports = class BankLetter { constructor({ client, @@ -55,13 +61,7 @@ module.exports = class BankLetter { async serialize(path) { const letter = await this.generate(); - - try { - fs.writeFileSync(path, letter); - } catch (error) { - throw error; - } - - return new Promise(resolve => resolve(true)); + await writeFile(path, letter); + return true; } };