| @@ -3,8 +3,26 @@ | ||
| 3 | 3 | import { useImageGenerationStore } from '@shared/state/generate-images'; |
| 4 | 4 | import apiFetch from '@wordpress/api-fetch'; |
| 5 | 5 | import { __ } from '@wordpress/i18n'; |
| 6 | 6 | |
| 7 | +const imageErrorMessage = (status) => { | |
| 8 | + if (status === 'content_policy_violation') { | |
| 9 | + // translators: shown when the AI image generator refuses a prompt on safety grounds. | |
| 10 | + return __( | |
| 11 | + 'That request was blocked by our safety system. Try a different description.', | |
| 12 | + 'extendify-local', | |
| 13 | + ); | |
| 14 | + } | |
| 15 | + if (status === 'no_image_returned') { | |
| 16 | + // translators: shown when the AI image generator returns nothing, cause unknown. | |
| 17 | + return __( | |
| 18 | + "Couldn't create that image. Try describing it differently.", | |
| 19 | + 'extendify-local', | |
| 20 | + ); | |
| 21 | + } | |
| 22 | + return __('Service temporarily unavailable', 'extendify-local'); | |
| 23 | +}; | |
| 24 | + | |
| 7 | 25 | export const generateImage = async (imageData, signal) => { |
| 8 | 26 | const response = await fetch(`${AI_HOST}/api/draft/image`, { |
| 9 | 27 | method: 'POST', |
| 10 | 28 | mode: 'cors', |
| @@ -25,21 +43,9 @@ | ||
| 25 | 43 | refresh: response.headers.get('x-ratelimit-reset'), |
| 26 | 44 | }; |
| 27 | 45 | |
| 28 | 46 | if (!response.ok) { |
| 29 | - if (body.status && body.status === 'content-policy-violation') { | |
| 30 | - throw { | |
| 31 | - message: __( | |
| 32 | - 'Your request was rejected as a result of our safety system. Your prompt may contain text that is not allowed by our safety system.', | |
| 33 | - 'extendify-local', | |
| 34 | - ), | |
| 35 | - imageCredits, | |
| 36 | - }; | |
| 37 | - } | |
| 38 | - throw { | |
| 39 | - message: __('Service temporarily unavailable', 'extendify-local'), | |
| 40 | - imageCredits, | |
| 41 | - }; | |
| 47 | + throw { message: imageErrorMessage(body.status), imageCredits }; | |
| 42 | 48 | } |
| 43 | 49 | return { |
| 44 | 50 | images: body, |
| 45 | 51 | imageCredits, |