add better error handeling :3

This commit is contained in:
Ashley 2023-04-19 18:55:04 +00:00
parent fd1fead07f
commit 022d706afa

View file

@ -1,22 +1,5 @@
const { const { fetcher, core, wiki, musicInfo, modules, version, initlog, init, } = require("../libpoketube-initsys.js");
fetcher, const { IsJsonString, convert, getFirstLine, capitalizeFirstLetter, turntomins, getRandomInt, getRandomArbitrary} = require("../ptutils/libpt-coreutils.js");
core,
wiki,
musicInfo,
modules,
version,
initlog,
init,
} = require("../libpoketube-initsys.js");
const {
IsJsonString,
convert,
getFirstLine,
capitalizeFirstLetter,
turntomins,
getRandomInt,
getRandomArbitrary,
} = require("../ptutils/libpt-coreutils.js");
const media_proxy = require("../libpoketube-video.js"); const media_proxy = require("../libpoketube-video.js");
const atmos = require("../../../pokeatmosurls.json"); const atmos = require("../../../pokeatmosurls.json");
@ -182,7 +165,7 @@ module.exports = function (app, config, renderTemplate) {
const isVideoValid = await core.isvalidvideo(v); const isVideoValid = await core.isvalidvideo(v);
if (!isVideoValid) { if (!isVideoValid) {
return res.redirect("/?fromerror=21"); return res.redirect("/?fromerror=21_video_not_valid");
} }
const u = await media_proxy(v); const u = await media_proxy(v);
@ -202,8 +185,6 @@ module.exports = function (app, config, renderTemplate) {
}); });
} }
core.video(v).then((data) => { core.video(v).then((data) => {
try { try {
const k = data.video; const k = data.video;
@ -235,13 +216,11 @@ module.exports = function (app, config, renderTemplate) {
if(inv_vid?.error === "The uploader has not made this video available in your country"){ if(inv_vid?.error === "The uploader has not made this video available in your country"){
res.send("error : " + inv_vid.error + " please refresh the page please qt ") res.send("error : " + inv_vid.error + " please refresh the page please qt ")
} }
if(inv_vid?.error === "This video is not available"){ if(inv_vid?.error === "This video is not available"){
res.send("error : " + inv_vid.error + " please refresh the page please qt ") res.send("error : " + inv_vid.error + " please refresh the page please qt ")
} }
renderTemplate(res, req, "poketube.ejs", { renderTemplate(res, req, "poketube.ejs", {
color: data.color, color: data.color,
color2: data.color2, color2: data.color2,
@ -279,7 +258,7 @@ module.exports = function (app, config, renderTemplate) {
}); });
} catch (error) { } catch (error) {
console.error(error); console.error(error);
return res.redirect("/?fromerror=41"); return res.redirect("/?fromerror=41_generic_error");
} }
}); });
}); });
@ -291,18 +270,7 @@ module.exports = function (app, config, renderTemplate) {
const info = await modules.fetch("http://ip-api.com/json/"); const info = await modules.fetch("http://ip-api.com/json/");
const ip = await info.json(); const ip = await info.json();
const { const {video: k,json,engagement,comments: inv_comments,vid: inv_vid,} = await core.video(v);
video: k,
json,
engagement,
comments: inv_comments,
vid: inv_vid,
} = await core.video(v);
if (!k || !json || !json.Title) {
res.redirect("/");
return;
}
const data = await core.video(v); const data = await core.video(v);
const color = data.color; const color = data.color;
@ -315,11 +283,6 @@ module.exports = function (app, config, renderTemplate) {
const d = desc.toString().replace(/\n/g, " <br> "); const d = desc.toString().replace(/\n/g, " <br> ");
const comments = inv_comments || "Disabled"; const comments = inv_comments || "Disabled";
const url =
q === "medium"
? `https://inv.vern.cc/latest_version?id=${v}&itag=18&local=true`
: null;
const templateData = { const templateData = {
color, color,
color2, color2,
@ -353,7 +316,7 @@ module.exports = function (app, config, renderTemplate) {
renderTemplate(res, req, "lite.ejs", templateData); renderTemplate(res, req, "lite.ejs", templateData);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
res.redirect("/"); res.redirect("/?err=" + error);
} }
}); });