From 5ca91af393c9b971b74b7bf8ca5900dcb95c0efb Mon Sep 17 00:00:00 2001 From: Ashley Date: Sat, 31 Dec 2022 12:39:51 +0000 Subject: [PATCH] add try catch :p --- .../init/pages-channel-and-download.js | 66 ++++++++++--------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/src/libpoketube/init/pages-channel-and-download.js b/src/libpoketube/init/pages-channel-and-download.js index 31b114f..c6621b7 100644 --- a/src/libpoketube/init/pages-channel-and-download.js +++ b/src/libpoketube/init/pages-channel-and-download.js @@ -79,39 +79,43 @@ module.exports = function (app, config, renderTemplate) { } if (query) { - const search = await modules.fetch( - `https://tube-srv.ashley143.gay/api/search?query=${query.replace( - "&", - "and" - )}&continuation=${continuation}` - ); - - const text = await search.text(); - const j = JSON.parse(modules.toJson(text)); - - h = " "; - - if (j.Search) { - if ("Results.DynamicItem" in j.Search) { - if (j.Search.Results.DynamicItem.id == "didYouMeanRenderer") { - var h = JSON.parse(j.Search.Results.DynamicItem.Title); - } - } - } - - const summary = await wiki - .summary(query + " ") - .then((summary_) => - summary_.title !== "Not found." ? summary_ : "none" + try { + const search = await modules.fetch( + `https://tube-srv.ashley143.gay/api/search?query=${query.replace( + "&", + "and" + )}&continuation=${continuation}` ); - renderTemplate(res, req, "search.ejs", { - j, - h, - continuation, - q: query, - summary, - }); + const text = await search.text(); + const j = JSON.parse(modules.toJson(text)); + + h = " "; + + if (j.Search) { + if ("Results.DynamicItem" in j.Search) { + if (j.Search.Results.DynamicItem.id == "didYouMeanRenderer") { + var h = JSON.parse(j.Search.Results.DynamicItem.Title); + } + } + } + + const summary = await wiki + .summary(query + " ") + .then((summary_) => + summary_.title !== "Not found." ? summary_ : "none" + ); + + renderTemplate(res, req, "search.ejs", { + j, + h, + continuation, + q: query, + summary, + }); + } catch { + res.redirect("/"); + } } });