From f07291b72cb00de591fa1b0df6c7f60eba8d5074 Mon Sep 17 00:00:00 2001 From: Sag Date: Wed, 22 Jan 2025 14:26:49 +0700 Subject: [PATCH] Added missing error message handler for the integrity token endpoint (#22043) ref https://linear.app/ghost/issue/PRO-1349 - the integrity token endpoint can return a json response with an error message (for example, when rate limited) - added the standard response handler to the integrity token endpoint in Portal, to render the error message sent by the backend --- apps/portal/src/utils/api.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/portal/src/utils/api.js b/apps/portal/src/utils/api.js index aabea5aa7a89..55bd0a8536ad 100644 --- a/apps/portal/src/utils/api.js +++ b/apps/portal/src/utils/api.js @@ -254,6 +254,10 @@ function setupGhostApi({siteUrl = window.location.origin, apiUrl, apiKey}) { if (res.ok) { return res.text(); } else { + const humanError = await HumanReadableError.fromApiResponse(res); + if (humanError) { + throw humanError; + } throw new Error('Failed to start a members session'); } }, @@ -290,7 +294,6 @@ function setupGhostApi({siteUrl = window.location.origin, apiUrl, apiKey}) { if (res.ok) { return 'Success'; } else { - // Try to read body error message that is human readable and should be shown to the user const humanError = await HumanReadableError.fromApiResponse(res); if (humanError) { throw humanError;