Add more information on error messages

This commit is contained in:
Leandro Facchinetti 2020-03-31 16:51:32 -04:00
parent 8b36080587
commit 9692192df4
2 changed files with 24 additions and 5 deletions

View File

@ -1,6 +1,7 @@
import * as xmlbuilder2 from "xmlbuilder2"; import * as xmlbuilder2 from "xmlbuilder2";
import fs from "fs"; import fs from "fs";
console.log("STARTED");
for (const feed of fs for (const feed of fs
.readdirSync("static/feeds") .readdirSync("static/feeds")
.filter(file => !file.startsWith("."))) { .filter(file => !file.startsWith("."))) {

View File

@ -20,9 +20,11 @@ export const webServer = express()
) )
) )
.post("/", (req, res, next) => { .post("/", (req, res, next) => {
let name: string;
let identifier: string;
(async () => { (async () => {
const name = req.body.name; name = req.body.name;
const identifier = createIdentifier(); identifier = createIdentifier();
await fs.writeFile( await fs.writeFile(
feedPath(identifier), feedPath(identifier),
renderXML(Feed({ name, identifier })) renderXML(Feed({ name, identifier }))
@ -35,7 +37,16 @@ export const webServer = express()
</Layout> </Layout>
) )
); );
})().catch(next); })().catch(error => {
console.error(
`Error creating feed: ${JSON.stringify(
{ name, identifier, error },
null,
2
)}`
);
next(error);
});
}) })
.get("/entry", (req, res) => .get("/entry", (req, res) =>
res.send( res.send(
@ -67,8 +78,9 @@ export const webServer = express()
export const emailServer = new SMTPServer({ export const emailServer = new SMTPServer({
disabledCommands: ["AUTH", "STARTTLS"], disabledCommands: ["AUTH", "STARTTLS"],
onData(stream, session, callback) { onData(stream, session, callback) {
let email: mailparser.ParsedMail;
(async () => { (async () => {
const email = await mailparser.simpleParser(stream); email = await mailparser.simpleParser(stream);
const { entry } = Entry({ const { entry } = Entry({
title: email.subject ?? "", title: email.subject ?? "",
author: email.from?.text ?? "", author: email.from?.text ?? "",
@ -93,7 +105,13 @@ export const emailServer = new SMTPServer({
} }
callback(); callback();
})().catch(error => { })().catch(error => {
console.error(error); console.error(
`Error receiving email: ${JSON.stringify(
{ session, email, error },
null,
2
)}`
);
stream.resume(); stream.resume();
callback(new Error("Failed to receive message. Please try again.")); callback(new Error("Failed to receive message. Please try again."));
}); });