diff --git a/app/soapbox/features/ads/components/ad.tsx b/app/soapbox/features/ads/components/ad.tsx index c42eb3db5..75e649784 100644 --- a/app/soapbox/features/ads/components/ad.tsx +++ b/app/soapbox/features/ads/components/ad.tsx @@ -1,4 +1,5 @@ import { useQuery, useQueryClient } from '@tanstack/react-query'; +import axios from 'axios'; import React, { useState, useEffect, useRef } from 'react'; import { FormattedMessage } from 'react-intl'; @@ -24,9 +25,9 @@ const Ad: React.FC = ({ ad }) => { // Fetch the impression URL (if any) upon displaying the ad. // Don't fetch it more than once. - useQuery(['ads', 'impression', ad.impression], () => { + useQuery(['ads', 'impression', ad.impression], async () => { if (ad.impression) { - return fetch(ad.impression); + return await axios.get(ad.impression); } }, { cacheTime: Infinity, staleTime: Infinity }); diff --git a/app/soapbox/features/ads/providers/rumble.ts b/app/soapbox/features/ads/providers/rumble.ts index bc86e8686..68a006e00 100644 --- a/app/soapbox/features/ads/providers/rumble.ts +++ b/app/soapbox/features/ads/providers/rumble.ts @@ -1,3 +1,5 @@ +import axios from 'axios'; + import { getSettings } from 'soapbox/actions/settings'; import { getSoapboxConfig } from 'soapbox/actions/soapbox'; import { normalizeAd, normalizeCard } from 'soapbox/normalizers'; @@ -28,14 +30,13 @@ const RumbleAdProvider: AdProvider = { const endpoint = soapboxConfig.extensions.getIn(['ads', 'endpoint']) as string | undefined; if (endpoint) { - const response = await fetch(endpoint, { - headers: { - 'Accept-Language': settings.get('locale', '*') as string, - }, - }); + try { + const { data } = await axios.get(endpoint, { + headers: { + 'Accept-Language': settings.get('locale', '*') as string, + }, + }); - if (response.ok) { - const data = await response.json() as RumbleApiResponse; return data.ads.map(item => normalizeAd({ impression: item.impression, card: normalizeCard({ @@ -45,6 +46,8 @@ const RumbleAdProvider: AdProvider = { }), expires_at: new Date(item.expires * 1000), })); + } catch (e) { + // do nothing } } diff --git a/app/soapbox/features/ads/providers/truth.ts b/app/soapbox/features/ads/providers/truth.ts index 92f2e99f8..a9af3c0d7 100644 --- a/app/soapbox/features/ads/providers/truth.ts +++ b/app/soapbox/features/ads/providers/truth.ts @@ -1,3 +1,5 @@ +import axios from 'axios'; + import { getSettings } from 'soapbox/actions/settings'; import { normalizeCard } from 'soapbox/normalizers'; @@ -18,18 +20,19 @@ const TruthAdProvider: AdProvider = { const state = getState(); const settings = getSettings(state); - const response = await fetch('/api/v2/truth/ads?device=desktop', { - headers: { - 'Accept-Language': settings.get('locale', '*') as string, - }, - }); + try { + const { data } = await axios.get('/api/v2/truth/ads?device=desktop', { + headers: { + 'Accept-Language': settings.get('locale', '*') as string, + }, + }); - if (response.ok) { - const data = await response.json() as TruthAd[]; return data.map(item => ({ ...item, card: normalizeCard(item.card), })); + } catch (e) { + // do nothing } return []; diff --git a/app/soapbox/service-worker/web-push-notifications.ts b/app/soapbox/service-worker/web-push-notifications.ts index 872d255c6..8088ca902 100644 --- a/app/soapbox/service-worker/web-push-notifications.ts +++ b/app/soapbox/service-worker/web-push-notifications.ts @@ -1,3 +1,4 @@ +/* eslint-disable compat/compat */ import IntlMessageFormat from 'intl-messageformat'; import 'intl-pluralrules'; import unescape from 'lodash/unescape';