Skip to content

Commit

Permalink
Fix embed error case
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Feb 27, 2018
1 parent b9c48b0 commit 07c449b
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions blocks/library/embed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,31 +111,33 @@ function getEmbedBlockSettings( { title, icon, category = 'embed', transforms, k
const { setAttributes } = this.props;

this.setState( { error: false, fetching: true } );
wp.apiRequest( { path: `/oembed/1.0/proxy?${ stringify( { url } ) }` } ).then(
( obj ) => {
if ( this.unmounting ) {
return;
wp.apiRequest( { path: `/oembed/1.0/proxy?${ stringify( { url } ) }` } )
.then(
( obj ) => {
if ( this.unmounting ) {
return;
}

const { html, provider_name: providerName } = obj;
const providerNameSlug = kebabCase( toLower( providerName ) );
let { type } = obj;

if ( includes( html, 'class="wp-embedded-content" data-secret' ) ) {
type = 'wp-embed';
}
if ( html ) {
this.setState( { html, type, providerNameSlug } );
setAttributes( { type, providerNameSlug } );
} else if ( 'photo' === type ) {
this.setState( { html: this.getPhotoHtml( obj ), type, providerNameSlug } );
setAttributes( { type, providerNameSlug } );
}
this.setState( { fetching: false } );
},
() => {
this.setState( { fetching: false, error: true } );
}

const { html, provider_name: providerName } = obj;
const providerNameSlug = kebabCase( toLower( providerName ) );
let { type } = obj;

if ( includes( html, 'class="wp-embedded-content" data-secret' ) ) {
type = 'wp-embed';
}
if ( html ) {
this.setState( { html, type, providerNameSlug } );
setAttributes( { type, providerNameSlug } );
} else if ( 'photo' === type ) {
this.setState( { html: this.getPhotoHtml( obj ), type, providerNameSlug } );
setAttributes( { type, providerNameSlug } );
} else {
this.setState( { error: true } );
}
this.setState( { fetching: false } );
}
);
);
}

render() {
Expand Down

0 comments on commit 07c449b

Please sign in to comment.