From f3a57b33d58dccae55756385030998d89054c2e6 Mon Sep 17 00:00:00 2001 From: Denis Utkin Date: Sun, 27 Apr 2025 15:45:53 +0200 Subject: [PATCH] fixed more errors with instagram --- api/src/processing/services/instagram.js | 32 ++++++++++++++++-------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/api/src/processing/services/instagram.js b/api/src/processing/services/instagram.js index 4a1b9d6b..bb5fb844 100644 --- a/api/src/processing/services/instagram.js +++ b/api/src/processing/services/instagram.js @@ -136,21 +136,26 @@ export default function instagram(obj) { } async function requestHTML(id, cookie) { - const data = await fetch(`https://www.instagram.com/p/${id}/embed/captioned/`, { - headers: { - ...embedHeaders, - cookie - }, - dispatcher - }).then(r => r.text()).catch(() => {}); + try { + const data = await fetch(`https://www.instagram.com/p/${id}/embed/captioned/`, { + headers: { + ...embedHeaders, + cookie + }, + dispatcher + }).then(r => r.text()).catch(() => { + }); - let embedData = JSON.parse(data?.match(/"init",\[\],\[(.*?)\]\],/)[1]); + let embedData = JSON.parse(data?.match(/"init",\[\],\[(.*?)\]\],/)[1]); - if (!embedData || !embedData?.contextJSON) return false; + if (!embedData || !embedData?.contextJSON) return false; - embedData = JSON.parse(embedData.contextJSON); + embedData = JSON.parse(embedData.contextJSON); + return embedData; + }catch { + return null; + } - return embedData; } async function getGQLParams(id, cookie) { @@ -213,6 +218,7 @@ export default function instagram(obj) { } async function requestGQL(id, cookie) { + try{ const { headers, body } = await getGQLParams(id, cookie); const req = await fetch('https://www.instagram.com/graphql/query', { @@ -245,6 +251,10 @@ export default function instagram(obj) { .then(r => r.data) .catch(() => null) }; + } + catch { + return null; + } } async function getErrorContext(id) {