| @@ -4,13 +4,14 @@ | ||
| 4 | 4 | fetchWithTimeout, |
| 5 | 5 | retryTwice, |
| 6 | 6 | setStatus, |
| 7 | 7 | } from '@auto-launch/functions/helpers'; |
| 8 | +import { launchStrings } from '@auto-launch/strings'; | |
| 8 | 9 | import { AI_HOST } from '@constants'; |
| 10 | +import { digest } from '@shared/api/digest'; | |
| 9 | 11 | import { reqDataBasics } from '@shared/lib/data'; |
| 10 | -import { __ } from '@wordpress/i18n'; | |
| 11 | 12 | |
| 12 | -const fallback = { aiHeaders: [], aiBlogTitles: [] }; | |
| 13 | +const fallback = { aiHeaders: [], aiBlogTitles: [], heroDescription: '' }; | |
| 13 | 14 | const url = `${AI_HOST}/api/site-strings`; |
| 14 | 15 | const method = 'POST'; |
| 15 | 16 | const headers = { 'Content-Type': 'application/json' }; |
| 16 | 17 | |
| @@ -15,17 +16,29 @@ | ||
| 15 | 16 | const headers = { 'Content-Type': 'application/json' }; |
| 16 | 17 | |
| 17 | 18 | export const handleSiteStrings = async ({ siteProfile }) => { |
| 18 | 19 | // translators: this is for a action log UI. Keep it short |
| 19 | - setStatus(__('Generating site content ideas', 'extendify-local')); | |
| 20 | + setStatus(launchStrings().statusIdeas); | |
| 20 | 21 | |
| 21 | 22 | const body = JSON.stringify({ ...reqDataBasics, siteProfile }); |
| 22 | 23 | |
| 23 | 24 | const response = await retryTwice(() => |
| 24 | 25 | fetchWithTimeout(url, { method, headers, body }), |
| 25 | - ); | |
| 26 | + ).catch((error) => { | |
| 27 | + return { ok: false, statusText: error.message, status: 0 }; | |
| 28 | + }); | |
| 26 | 29 | |
| 27 | - if (!response?.ok) return fallback; | |
| 30 | + if (!response?.ok) { | |
| 31 | + digest({ | |
| 32 | + error: { | |
| 33 | + message: response.statusText, | |
| 34 | + name: 'FetchError', | |
| 35 | + status: response.status, | |
| 36 | + }, | |
| 37 | + details: { source: 'auto-launch', caller: 'handleSiteStrings' }, | |
| 38 | + }); | |
| 39 | + return fallback; | |
| 40 | + } | |
| 28 | 41 | |
| 29 | 42 | return failWithFallback( |
| 30 | 43 | async () => getStringsShape.parse(await response.json()), |
| 31 | 44 | fallback, |