Properly handle rejections
This commit is contained in:
parent
16f0b4e9fc
commit
b2a04b35af
12
main.js
12
main.js
@ -21,24 +21,20 @@ const dotenv = require('dotenv').config();
|
|||||||
if (process.env.ONPI == 'true') {
|
if (process.env.ONPI == 'true') {
|
||||||
console.log(`[${(Date.now() - config.startTime)/1000}] == Running on a Raspberry Pi.`);
|
console.log(`[${(Date.now() - config.startTime)/1000}] == Running on a Raspberry Pi.`);
|
||||||
const gpio = require('rpi-gpio');
|
const gpio = require('rpi-gpio');
|
||||||
fn.init(gpio).then((res, rej) => {
|
fn.init(gpio).then((res) => {
|
||||||
if (res != undefined) {
|
|
||||||
console.log(`[${(Date.now() - config.startTime)/1000}] I: ${res}`);
|
console.log(`[${(Date.now() - config.startTime)/1000}] I: ${res}`);
|
||||||
main(fn, gpio);
|
main(fn, gpio);
|
||||||
} else {
|
}).catch(rej => {
|
||||||
console.error(`[${(Date.now() - config.startTime)/1000}] E: ${rej}`);
|
console.error(`[${(Date.now() - config.startTime)/1000}] E: ${rej}`);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} else if (process.env.ONPI == 'false') {
|
} else if (process.env.ONPI == 'false') {
|
||||||
console.log(`[${(Date.now() - config.startTime)/1000}] I: Not running on a Raspberry Pi.`);
|
console.log(`[${(Date.now() - config.startTime)/1000}] I: Not running on a Raspberry Pi.`);
|
||||||
const gpio = 'gpio';
|
const gpio = 'gpio';
|
||||||
fn.init(gpio).then((res, rej) => {
|
fn.init(gpio).then(res => {
|
||||||
if (res != undefined) {
|
|
||||||
console.log(`[${(Date.now() - config.startTime)/1000}] I: ${res}`);
|
console.log(`[${(Date.now() - config.startTime)/1000}] I: ${res}`);
|
||||||
main(fn, gpio);
|
main(fn, gpio);
|
||||||
} else {
|
}).catch(rej => {
|
||||||
console.error(rej);
|
console.error(rej);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.error(`[${Date.now() - config.startTime}] E: Problem with ENV file.`);
|
console.error(`[${Date.now() - config.startTime}] E: Problem with ENV file.`);
|
||||||
|
Loading…
Reference in New Issue
Block a user