| @@ -5,11 +5,12 @@ | ||
| 5 | 5 | fetchWithTimeout, |
| 6 | 6 | retryTwice, |
| 7 | 7 | setStatus, |
| 8 | 8 | } from '@auto-launch/functions/helpers'; |
| 9 | +import { launchStrings } from '@auto-launch/strings'; | |
| 9 | 10 | import { IMAGES_HOST } from '@constants'; |
| 11 | +import { digest } from '@shared/api/digest'; | |
| 10 | 12 | import { reqDataBasics } from '@shared/lib/data'; |
| 11 | -import { __ } from '@wordpress/i18n'; | |
| 12 | 13 | |
| 13 | 14 | const fallback = { siteImages: { hero: [], general: [] } }; |
| 14 | 15 | const url = `${IMAGES_HOST}/api/images`; |
| 15 | 16 | const { wpLanguage } = window.extSharedData; |
| @@ -24,9 +25,9 @@ | ||
| 24 | 25 | const asSections = (urls) => ({ hero: [], general: asImages(urls) }); |
| 25 | 26 | |
| 26 | 27 | export const handleSiteImages = async ({ siteProfile, designBuild }) => { |
| 27 | 28 | // translators: this is for a action log UI. Keep it short |
| 28 | - setStatus(__('Finding the perfect images', 'extendify-local')); | |
| 29 | + setStatus(launchStrings().statusImages); | |
| 29 | 30 | |
| 30 | 31 | // Reuse the design preview's own images; only search for what is missing. |
| 31 | 32 | const seeded = collectBuiltPageImageUrls(designBuild?.builtPages); |
| 32 | 33 | if (seeded.length >= MIN_POOL_SIZE) return { siteImages: asSections(seeded) }; |
| @@ -40,11 +41,23 @@ | ||
| 40 | 41 | }); |
| 41 | 42 | |
| 42 | 43 | const response = await retryTwice(() => |
| 43 | 44 | fetchWithTimeout(url, { method, headers, body }), |
| 44 | - ); | |
| 45 | + ).catch((error) => { | |
| 46 | + return { ok: false, statusText: error.message, status: 0 }; | |
| 47 | + }); | |
| 45 | 48 | |
| 46 | - if (!response?.ok) return { siteImages: asSections(seeded) }; | |
| 49 | + if (!response?.ok) { | |
| 50 | + digest({ | |
| 51 | + error: { | |
| 52 | + message: response.statusText, | |
| 53 | + name: 'FetchError', | |
| 54 | + status: response.status, | |
| 55 | + }, | |
| 56 | + details: { source: 'auto-launch', caller: 'handleSiteImages' }, | |
| 57 | + }); | |
| 58 | + return { siteImages: asSections(seeded) }; | |
| 59 | + } | |
| 47 | 60 | |
| 48 | 61 | const { siteImages: found } = await failWithFallback( |
| 49 | 62 | async () => { |
| 50 | 63 | const { images } = await response.json(); |