Skip to content

Commit

Permalink
SDANSA-556 (#4434)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecalcc authored Feb 13, 2024
1 parent 2088b9a commit 194cded
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 8 additions & 2 deletions scripts/core/editor3/components/BaseUnstyledComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,15 @@ class BaseUnstyledComponent extends React.Component<IProps, IState> {
) {
getEmbedObject(link)
.then((oEmbed) => {
this.props.dispatch(embed(oEmbed, blockKey));
if (oEmbed) {
this.props.dispatch(embed(oEmbed, blockKey));
handled = true;
}
})
.catch((err) => {
notify.error(err.description ?? gettext('An unknown error ocurred.'));
handled = false;
});
handled = true;
} else if (isHtmlTextAndShouldCreateEmbed(event, mediaType, this.props.editorProps)) {
this.props.dispatch(embed(event.originalEvent.dataTransfer.getData(mediaType), blockKey));
handled = true;
Expand Down
11 changes: 11 additions & 0 deletions scripts/core/editor3/components/embeds/EmbedInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ export const getEmbedObject = (url) => {
return $.ajax({
url: `//iframe.ly/api/oembed?callback=?&url=${url}&api_key=${apiKey}&omit_script=true&iframe=true`,
dataType: 'json',
}).then((result) => {
/**
* No standard way of differentiating between an error and a valid response.
* An observation was made that if the result doesn't contain an html field,
* then the response is invalid. (SDANSA-556)
*/
if (result.html == null) {
return Promise.reject(result);
}

return result;
});
};

Expand Down

0 comments on commit 194cded

Please sign in to comment.