Prevent server from crashing when link is empty or invalid

This commit is contained in:
Ilango
2024-02-27 10:32:29 +05:30
parent 2290ba9cc0
commit c123b5f83a
+4
View File
@@ -1150,6 +1150,7 @@ export class App {
// ---------------------------------------- // ----------------------------------------
this.app.get('/api/v1/fetch-links', async (req: Request, res: Response) => { this.app.get('/api/v1/fetch-links', async (req: Request, res: Response) => {
try {
const url = decodeURIComponent(req.query.url as string) const url = decodeURIComponent(req.query.url as string)
const relativeLinksMethod = req.query.relativeLinksMethod as string const relativeLinksMethod = req.query.relativeLinksMethod as string
if (!relativeLinksMethod) { if (!relativeLinksMethod) {
@@ -1162,6 +1163,9 @@ export class App {
if (process.env.DEBUG === 'true') console.info(`Finish ${relativeLinksMethod}`) if (process.env.DEBUG === 'true') console.info(`Finish ${relativeLinksMethod}`)
res.json({ status: 'OK', links }) res.json({ status: 'OK', links })
} catch (e: any) {
return res.status(500).send('Could not fetch links from the URL.')
}
}) })
// ---------------------------------------- // ----------------------------------------