From ad6d6b79a47c7c689e9f49bdd1e891376d2dba9b Mon Sep 17 00:00:00 2001 From: JayWll Date: Sat, 11 Apr 2020 13:34:32 -0600 Subject: [PATCH] Adding error checking to import utility --- nodeapp/utils/import.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/nodeapp/utils/import.js b/nodeapp/utils/import.js index f7831e0..975a158 100644 --- a/nodeapp/utils/import.js +++ b/nodeapp/utils/import.js @@ -13,14 +13,15 @@ request({ 'export-key': process.env.SECRET }, json: true -}, (error, {body}) => { +}, async(error, response) => { if (error) return console.log(error) + if (response.statusCode != 200) return console.log('Unsuccessful, as indicated by HTTP status') - console.log(body.length + ' items retrieved') + console.log(response.body.length + ' items retrieved') // Remove existing database items - db.Readings.destroy({truncate: true}) + await db.Readings.destroy({truncate: true}) // Add new data to the database - db.Readings.bulkCreate(body) + await db.Readings.bulkCreate(response.body) });