diff --git a/projects/js-packages/ai-client/src/hooks/use-image-generator/index.ts b/projects/js-packages/ai-client/src/hooks/use-image-generator/index.ts index 5a4e75454ca80..92d6895862438 100644 --- a/projects/js-packages/ai-client/src/hooks/use-image-generator/index.ts +++ b/projects/js-packages/ai-client/src/hooks/use-image-generator/index.ts @@ -1,6 +1,7 @@ /** * External dependencies */ +import { __ } from '@wordpress/i18n'; import debugFactory from 'debug'; /** * Internal dependencies @@ -193,6 +194,16 @@ const useImageGenerator = () => { } ); + if ( ! response?.ok ) { + debug( 'Error generating image: %o', response ); + return Promise.reject( { + data: { + status: response.status, + }, + message: __( 'Error generating image. Please try again later.', 'jetpack-ai-client' ), + } ); + } + const blob = await response.blob(); /**