From b2a04b35af0f1535f167bcbdc9ba9f0f458d4cc3 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Thu, 8 Dec 2022 12:45:46 -0500 Subject: [PATCH] Properly handle rejections --- main.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/main.js b/main.js index 11b08f3..651c250 100644 --- a/main.js +++ b/main.js @@ -21,24 +21,20 @@ const dotenv = require('dotenv').config(); if (process.env.ONPI == 'true') { console.log(`[${(Date.now() - config.startTime)/1000}] == Running on a Raspberry Pi.`); const gpio = require('rpi-gpio'); - fn.init(gpio).then((res, rej) => { - if (res != undefined) { - console.log(`[${(Date.now() - config.startTime)/1000}] I: ${res}`); - main(fn, gpio); - } else { - console.error(`[${(Date.now() - config.startTime)/1000}] E: ${rej}`); - } + fn.init(gpio).then((res) => { + console.log(`[${(Date.now() - config.startTime)/1000}] I: ${res}`); + main(fn, gpio); + }).catch(rej => { + console.error(`[${(Date.now() - config.startTime)/1000}] E: ${rej}`); }); } else if (process.env.ONPI == 'false') { console.log(`[${(Date.now() - config.startTime)/1000}] I: Not running on a Raspberry Pi.`); const gpio = 'gpio'; - fn.init(gpio).then((res, rej) => { - if (res != undefined) { - console.log(`[${(Date.now() - config.startTime)/1000}] I: ${res}`); - main(fn, gpio); - } else { - console.error(rej); - } + fn.init(gpio).then(res => { + console.log(`[${(Date.now() - config.startTime)/1000}] I: ${res}`); + main(fn, gpio); + }).catch(rej => { + console.error(rej); }); } else { console.error(`[${Date.now() - config.startTime}] E: Problem with ENV file.`);