change error type to make more sense

This commit is contained in:
hyperdefined 2024-07-18 10:48:48 -04:00
parent d7b4ee6c06
commit beff9aaff6
No known key found for this signature in database
GPG Key ID: EB0B55B31E88AB03

View File

@ -13,7 +13,7 @@ export default async function(obj) {
.then(request => request.text()) .then(request => request.text())
.catch(() => {}); .catch(() => {});
if (!req) return { error: 'ErrorEmptyDownload' }; if (!req) return { error: 'ErrorCouldntFetch' };
let json; let json;
try { try {
@ -22,7 +22,7 @@ export default async function(obj) {
const highestQuality = Object.keys(json.sources)[0]; const highestQuality = Object.keys(json.sources)[0];
const video = json.sources[highestQuality][0].src; const video = json.sources[highestQuality][0].src;
if (!json.sources[highestQuality][0].type.includes('mp4')) { if (!json.sources[highestQuality][0].type.includes('mp4')) {
return { error: 'ErrorEmptyDownload' }; return { error: 'ErrorCouldntFetch' };
} }
let fileMetadata = { let fileMetadata = {
@ -53,14 +53,14 @@ export default async function(obj) {
.then(request => request.text()) .then(request => request.text())
.catch(() => {}); .catch(() => {});
if (!req) return { error: 'ErrorEmptyDownload' }; if (!req) return { error: 'ErrorCouldntFetch' };
const titleMatch = req.match(/"name"\s*:\s*"([^"]+)"/); const titleMatch = req.match(/"name"\s*:\s*"([^"]+)"/);
const artistMatch = req.match(/"artist"\s*:\s*"([^"]+)"/); const artistMatch = req.match(/"artist"\s*:\s*"([^"]+)"/);
const urlMatch = req.match(/"filename"\s*:\s*"([^"]+)"/); const urlMatch = req.match(/"filename"\s*:\s*"([^"]+)"/);
if (!titleMatch || !artistMatch || !urlMatch) { if (!titleMatch || !artistMatch || !urlMatch) {
return { error: 'ErrorEmptyDownload' }; return { error: 'ErrorCouldntFetch' };
} }
const title = titleMatch[1]; const title = titleMatch[1];