From 7dce7986483c250f2daa69ce18db5558b4fec5b6 Mon Sep 17 00:00:00 2001 From: dangered wolf Date: Thu, 6 Apr 2023 17:56:21 -0400 Subject: [PATCH] Bug fix fallback --- .env.example | 2 +- src/api/status.ts | 6 +++--- src/fetch.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index e0f9351..11eb342 100644 --- a/.env.example +++ b/.env.example @@ -13,4 +13,4 @@ SENTRY_DSN = "" SENTRY_AUTH_TOKEN = "" SENTRY_ORG = "" SENTRY_PROJECT = "" -API_FALLBACK_DOMAIN = "" \ No newline at end of file +API_FALLBACK_DOMAIN = "https://" \ No newline at end of file diff --git a/src/api/status.ts b/src/api/status.ts index 32a56fb..8f2d482 100644 --- a/src/api/status.ts +++ b/src/api/status.ts @@ -141,7 +141,7 @@ export const statusAPI = async ( language: string | undefined, event: FetchEvent ): Promise => { - const conversation = await fetchConversation(status, event); + let conversation = await fetchConversation(status, event); let tweet = conversation?.globalObjects?.tweets?.[status] || {}; if (tweet.retweeted_status_id_str) { @@ -156,8 +156,8 @@ export const statusAPI = async ( if (conversation.timeline?.instructions?.length > 0) { // Try request again with fallback this time console.log('No Tweet was found, trying fallback in case of geo-restriction'); - const conversationFallback = await fetchConversation(status, event, true); - tweet = conversationFallback?.globalObjects?.tweets?.[status] || {}; + conversation = await fetchConversation(status, event, true); + tweet = conversation?.globalObjects?.tweets?.[status] || {}; if (typeof tweet.full_text !== 'undefined') { console.log('Successfully loaded Tweet, requiring fallback'); diff --git a/src/fetch.ts b/src/fetch.ts index e5eda06..da2cc79 100644 --- a/src/fetch.ts +++ b/src/fetch.ts @@ -125,7 +125,7 @@ export const twitterFetch = async ( } catch (e: unknown) { /* We'll usually only hit this if we get an invalid response from Twitter. It's uncommon, but it happens */ - console.error('Unknown error while fetching from API'); + console.error('Unknown error while fetching from API', e); event && event.waitUntil( cache.delete(guestTokenRequestCacheDummy.clone(), { ignoreMethod: true })