Skip to content

Commit

Permalink
Report error when URLs can't be embedded and don't generate a fallback (
Browse files Browse the repository at this point in the history
  • Loading branch information
notnownikki authored Oct 10, 2018
1 parent f232447 commit 49f8f2b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/block-library/src/embed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ export function getEmbedEdit( title, icon ) {
const { url, editingURL } = this.state;
const { caption, type, allowResponsive } = this.props.attributes;
const { fetching, setAttributes, isSelected, className, preview, previewIsFallback } = this.props;
// We have a URL, but couldn't get a preview, or the preview was the oEmbed fallback.
const cannotEmbed = url && ( ! preview || previewIsFallback );
const controls = (
<Fragment>
<BlockControls>
Expand Down Expand Up @@ -313,7 +315,7 @@ export function getEmbedEdit( title, icon ) {
type="submit">
{ __( 'Embed' ) }
</Button>
{ previewIsFallback && <p className="components-placeholder__error">{ __( 'Sorry, we could not embed that content.' ) }</p> }
{ cannotEmbed && <p className="components-placeholder__error">{ __( 'Sorry, we could not embed that content.' ) }</p> }
</form>
</Placeholder>
);
Expand Down Expand Up @@ -412,8 +414,12 @@ function getEmbedBlockSettings( { title, description, icon, category = 'embed',
const preview = url && getEmbedPreview( url );
const previewIsFallback = url && isPreviewEmbedFallback( url );
const fetching = undefined !== url && isRequestingEmbedPreview( url );
// Some WordPress URLs that can't be embedded will cause the API to return
// a valid JSON response with no HTML and `data.status` set to 404, rather
// than generating a fallback response as other embeds do.
const validPreview = preview && ! ( preview.data && preview.data.status === 404 );
return {
preview,
preview: validPreview && preview,
previewIsFallback,
fetching,
};
Expand Down

0 comments on commit 49f8f2b

Please sign in to comment.