Basic error checking

This commit is contained in:
Cadence Fish
2020-01-27 19:03:28 +13:00
parent c2ac1b2259
commit 9f5fa84f9a
9 changed files with 156 additions and 49 deletions

View File

@@ -3,14 +3,25 @@ const {fetchUser} = require("../../lib/collectors")
const {render} = require("pinski/plugins")
module.exports = [
{route: `/u/(${constants.external.username_regex})/rss.xml`, methods: ["GET"], code: async ({url, fill}) => {
const user = await fetchUser(fill[0])
const content = await user.timeline.fetchFeed()
const xml = content.xml()
return {
statusCode: 200,
contentType: "application/rss+xml", // see https://stackoverflow.com/questions/595616/what-is-the-correct-mime-type-to-use-for-an-rss-feed
content: xml
}
{route: `/u/(${constants.external.username_regex})/rss.xml`, methods: ["GET"], code: ({fill}) => {
return fetchUser(fill[0]).then(async user => {
const content = await user.timeline.fetchFeed()
const xml = content.xml()
return {
statusCode: 200,
contentType: "application/rss+xml", // see https://stackoverflow.com/questions/595616/what-is-the-correct-mime-type-to-use-for-an-rss-feed
content: xml
}
}).catch(error => {
if (error === constants.symbols.NOT_FOUND) {
return render(404, "pug/friendlyerror.pug", {
statusCode: 404,
title: "Not found",
message: "This user doesn't exist."
})
} else {
throw error
}
})
}}
]