From caa378bd0215d4e71a9c47278282d5f6de234fc5 Mon Sep 17 00:00:00 2001 From: Luiz Kowalski Date: Thu, 16 May 2024 16:35:18 -0300 Subject: [PATCH] Add error handling to the image generation request --- .../ai-client/src/hooks/use-image-generator/index.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) 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(); /**