Skip to content

Commit

Permalink
Add error handling to the image generation request
Browse files Browse the repository at this point in the history
  • Loading branch information
lhkowalski committed May 16, 2024
1 parent 91f70de commit caa378b
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import debugFactory from 'debug';
/**
* Internal dependencies
Expand Down Expand Up @@ -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();

/**
Expand Down

0 comments on commit caa378b

Please sign in to comment.