Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post publish upload media dialog: handle upload errors #64823

Merged
merged 5 commits into from
Aug 28, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ function Image( block ) {
export default function PostFormatPanel() {
const [ isUploading, setIsUploading ] = useState( false );
const [ isAnimating, setIsAnimating ] = useState( false );
const [ hadUploadError, setHadUploadError ] = useState( false );
const { editorBlocks, mediaUpload } = useSelect(
( select ) => ( {
editorBlocks: select( blockEditorStore ).getBlocks(),
Expand Down Expand Up @@ -89,6 +90,7 @@ export default function PostFormatPanel() {

function uploadImages() {
setIsUploading( true );
setHadUploadError( false );
Promise.all(
externalImages.map( ( image ) =>
window
Expand All @@ -114,6 +116,7 @@ export default function PostFormatPanel() {
resolve();
},
onError() {
setHadUploadError( true );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only catches errors from media upload; we also need to catch errors for window.fetch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This promise chain is getting fun 😄

I added a catch-all to the end of each individual upload. That should catch any errors / rejections, whether they come from the window.fetch or one of the later steps.

How does that look?

reject();
},
} );
Expand Down Expand Up @@ -154,6 +157,7 @@ export default function PostFormatPanel() {
</Button>
) }
</div>
{ hadUploadError && <p>{ __( 'Upload failed, try again.' ) }</p> }
</PanelBody>
);
}
Loading