diff --git a/src/js/openai/classic-editor-excerpt-generator.js b/src/js/openai/classic-editor-excerpt-generator.js index e093271d8..df4fe7f19 100644 --- a/src/js/openai/classic-editor-excerpt-generator.js +++ b/src/js/openai/classic-editor-excerpt-generator.js @@ -40,6 +40,12 @@ const classifaiExcerptData = window.classifaiGenerateExcerpt || {}; ) .insertAfter( excerptContainer ); + $( '
', { + class: 'classifai-openai__excerpt-generate-error', + } ).insertAfter( + document.getElementById( 'classifai-openai__excerpt-generate-btn' ) + ); + // Append disable feature link. if ( ClassifAI?.opt_out_enabled_features?.includes( @@ -79,25 +85,34 @@ const classifaiExcerptData = window.classifaiGenerateExcerpt || {}; const spinnerEl = $( '.classifai-openai__excerpt-generate-btn--spinner' ); + const errorEl = $( '.classifai-openai__excerpt-generate-error' ); generateTextEl.css( 'opacity', '0' ); spinnerEl.show(); + errorEl.text( '' ).hide(); isProcessing = true; const path = classifaiExcerptData?.path + postId; apiFetch( { path, - } ).then( ( result ) => { - generateTextEl.css( 'opacity', '1' ); - spinnerEl.hide(); - isProcessing = false; + } ) + .then( ( result ) => { + generateTextEl.css( 'opacity', '1' ); + spinnerEl.hide(); + isProcessing = false; - $( excerptContainer ).val( result ).trigger( 'input' ); - generateTextEl.text( - classifaiExcerptData?.regenerateText ?? '' - ); - } ); + $( excerptContainer ).val( result ).trigger( 'input' ); + generateTextEl.text( + classifaiExcerptData?.regenerateText ?? '' + ); + } ) + .catch( ( error ) => { + generateTextEl.css( 'opacity', '1' ); + spinnerEl.hide(); + isProcessing = false; + errorEl.text( error?.message ).show(); + } ); }; // Event handler registration to generate the excerpt. diff --git a/src/js/openai/classic-editor-title-generator.js b/src/js/openai/classic-editor-title-generator.js index ed7a3162a..dcfe7e5ab 100644 --- a/src/js/openai/classic-editor-title-generator.js +++ b/src/js/openai/classic-editor-title-generator.js @@ -104,54 +104,71 @@ const scriptData = classifaiChatGPTData.enabledFeatures.reduce( apiFetch( { path, - } ).then( ( result ) => { - generateTextEl.css( 'opacity', '1' ); - spinnerEl.hide(); - isProcessing = false; - - result.forEach( ( title ) => { - $( '