From 947736519503d6df1065dfb1e67a750204e46030 Mon Sep 17 00:00:00 2001 From: Ed Gargan Date: Mon, 13 May 2024 15:31:50 +0100 Subject: [PATCH] fix: don't fetch highlights token when no highlights present --- components/x-gift-article/src/SharingOptionsToggler.jsx | 1 - components/x-gift-article/src/lib/highlightsApi.js | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/components/x-gift-article/src/SharingOptionsToggler.jsx b/components/x-gift-article/src/SharingOptionsToggler.jsx index 8d3090f5f..f47c78a71 100644 --- a/components/x-gift-article/src/SharingOptionsToggler.jsx +++ b/components/x-gift-article/src/SharingOptionsToggler.jsx @@ -18,7 +18,6 @@ export const SharingOptionsToggler = (props) => { actions.showAdvancedSharingOptions() } else { actions.hideNonSubscriberSharingOptions(event) - actions.setIncludeHighlights(event.target.checked) } return } diff --git a/components/x-gift-article/src/lib/highlightsApi.js b/components/x-gift-article/src/lib/highlightsApi.js index b4a75e29e..cbe509909 100644 --- a/components/x-gift-article/src/lib/highlightsApi.js +++ b/components/x-gift-article/src/lib/highlightsApi.js @@ -38,6 +38,11 @@ export default class HighlightsApiClient { ) const response = await fetch(url, options) + + if (!response.ok) { + throw new Error(`failed to fetch ${url}, received ${response.status}`) + } + const responseJSON = await response.json() return responseJSON } @@ -62,6 +67,7 @@ export default class HighlightsApiClient { if (!includeHighlights) { return {} } + return await this.fetchJson('/create-token', { method: 'POST', body: JSON.stringify({ articleId })