diff --git a/lib/imgur.js b/lib/imgur.js index 2d963458..95da3e93 100644 --- a/lib/imgur.js +++ b/lib/imgur.js @@ -4,6 +4,7 @@ const got = require('got'); const util = require('util'); const fs = require('fs'); const readFile = util.promisify(fs.readFile); +const writeFile = util.promisify(fs.writeFile); const FormData = require('form-data'); const VERSION = require('../package.json').version; @@ -263,13 +264,11 @@ imgur.loadClientId = async (path) => { imgur.saveClientId = async (clientId, path) => { path = path || DEFAULT_CLIENT_ID_PATH; - fs.writeFile(path, clientId, (err) => { - if (err) { - throw new Error(err); - } - - return; - }); + try { + await writeFile(path, clientId); + } catch (e) { + throw new Error(e.message); + } }; /**