From 9692192df42cf18e86bedc959f2658a1cfc898c1 Mon Sep 17 00:00:00 2001 From: Leandro Facchinetti Date: Tue, 31 Mar 2020 16:51:32 -0400 Subject: [PATCH] Add more information on error messages --- src/check.ts | 1 + src/index.tsx | 28 +++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/check.ts b/src/check.ts index 1a82570..16ce00a 100644 --- a/src/check.ts +++ b/src/check.ts @@ -1,6 +1,7 @@ import * as xmlbuilder2 from "xmlbuilder2"; import fs from "fs"; +console.log("STARTED"); for (const feed of fs .readdirSync("static/feeds") .filter(file => !file.startsWith("."))) { diff --git a/src/index.tsx b/src/index.tsx index b98ecfa..43f9fcf 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -20,9 +20,11 @@ export const webServer = express() ) ) .post("/", (req, res, next) => { + let name: string; + let identifier: string; (async () => { - const name = req.body.name; - const identifier = createIdentifier(); + name = req.body.name; + identifier = createIdentifier(); await fs.writeFile( feedPath(identifier), renderXML(Feed({ name, identifier })) @@ -35,7 +37,16 @@ export const webServer = express() ) ); - })().catch(next); + })().catch(error => { + console.error( + `Error creating feed: ${JSON.stringify( + { name, identifier, error }, + null, + 2 + )}` + ); + next(error); + }); }) .get("/entry", (req, res) => res.send( @@ -67,8 +78,9 @@ export const webServer = express() export const emailServer = new SMTPServer({ disabledCommands: ["AUTH", "STARTTLS"], onData(stream, session, callback) { + let email: mailparser.ParsedMail; (async () => { - const email = await mailparser.simpleParser(stream); + email = await mailparser.simpleParser(stream); const { entry } = Entry({ title: email.subject ?? "", author: email.from?.text ?? "", @@ -93,7 +105,13 @@ export const emailServer = new SMTPServer({ } callback(); })().catch(error => { - console.error(error); + console.error( + `Error receiving email: ${JSON.stringify( + { session, email, error }, + null, + 2 + )}` + ); stream.resume(); callback(new Error("Failed to receive message. Please try again.")); });