Skip to content

Commit

Permalink
Media3P: Add hardening for missing media URLs (#12091)
Browse files Browse the repository at this point in the history
Co-authored-by: Pascal Birchler <pascalb@google.com>
  • Loading branch information
timarney and swissspidy authored Aug 16, 2022
1 parent 91107c9 commit f9b26d9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
import { useEffect, useRef } from '@googleforcreators/react';
import { useSnackbar } from '@googleforcreators/design-system';
import { trackError } from '@googleforcreators/tracking';

/**
* Internal dependencies
Expand Down Expand Up @@ -99,6 +100,9 @@ export default function useFetchMediaEffect({
nextPageToken,
});
} catch (e) {
// eslint-disable-next-line no-console -- We want to surface this error.
console.error(e);
trackError('fetch_media3p', e.message);
fetchMediaError({ provider, pageToken });
showSnackbar({
message: PROVIDERS[provider].fetchMediaErrorMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ function getVideoUrls(m) {
}

function sortMediaBySize(m, mediaUrls) {
// https://github.com/GoogleForCreators/web-stories-wp/issues/12083
if (mediaUrls.length < 1) {
return [];
}

const sortedUrls = mediaUrls.sort((x, y) => (y.width ?? 0) - (x.width ?? 0));
const originalSize = getOriginalSize(sortedUrls);
return sortedUrls.map((u) =>
Expand Down

0 comments on commit f9b26d9

Please sign in to comment.