From b5fd940429ef58795da13f1a1dae784cb6c16df0 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sat, 7 Jul 2018 22:31:41 +0000 Subject: [PATCH] check sendMail return code --- lib/extensions/index.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/extensions/index.js b/lib/extensions/index.js index 5cf5e9b..46d3084 100644 --- a/lib/extensions/index.js +++ b/lib/extensions/index.js @@ -10,6 +10,13 @@ var requestAsync = util.promisify(require('@coolaj86/urequest')); var readFileAsync = util.promisify(fs.readFile); var mkdirpAsync = util.promisify(require('mkdirp')); +var PromiseA; +try { + PromiseA = require('bluebird'); +} catch(e) { + PromiseA = global.Promise; +} + var _auths = module.exports._auths = {}; var Auths = {}; Auths._no_pin = { @@ -200,8 +207,15 @@ function sendMail(state, auth) { console.error(err); } }); - console.log("[DEBUG] email was sent, or so they say"); - console.log(resp.body); + // anything in the 200 range + if (2 === Math.floor(resp.statusCode / 100)) { + console.log("[DEBUG] email was sent, or so they say"); + } else { + console.error("[Error] email failed to send, or so they say:"); + console.error(resp.headers); + console.error(resp.statusCode, resp.body); + return PromiseA.reject(new Error("Error sending email: " + resp.statusCode + " " + resp.body)); + } }); }