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 fs from "fs";
console.log("STARTED");
for (const feed of fs
.readdirSync("static/feeds")
.filter(file => !file.startsWith("."))) {

View File

@ -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()
</Layout>
)
);
})().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."));
});