Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Commit

Permalink
Try/catch profile pic (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondjacobson committed May 4, 2021
1 parent 53fa3ca commit 2111e13
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
21 changes: 13 additions & 8 deletions src/containers/sign-on/components/desktop/ProfilePage.js
Expand Up @@ -107,14 +107,19 @@ export class ProfilePage extends Component {
onInstagramLogin = async (uuid, profile) => {
try {
if (profile.profile_pic_url_hd) {
const profileUrl = profile.profile_pic_url_hd
const imageBlob = await fetch(profileUrl).then(r => r.blob())
const artworkFile = new File([imageBlob], 'Artwork', {
type: 'image/jpeg'
})
const file = await resizeImage(artworkFile)
const url = URL.createObjectURL(file)
this.props.setInstagramProfile(uuid, profile, { url, file })
try {
const profileUrl = profile.profile_pic_url_hd
const imageBlob = await fetch(profileUrl).then(r => r.blob())
const artworkFile = new File([imageBlob], 'Artwork', {
type: 'image/jpeg'
})
const file = await resizeImage(artworkFile)
const url = URL.createObjectURL(file)
this.props.setInstagramProfile(uuid, profile, { url, file })
} catch (e) {
console.error('Failed to fetch profile_pic_url_hd', e)
this.props.setInstagramProfile(uuid, profile)
}
} else {
this.props.setInstagramProfile(uuid, profile)
}
Expand Down
21 changes: 13 additions & 8 deletions src/containers/sign-on/components/mobile/ProfilePage.tsx
Expand Up @@ -142,14 +142,19 @@ const ProfilePage = (props: ProfilePageProps) => {
const onInstagramLogin = async (uuid: string, profile: InstagramProfile) => {
try {
if (profile.profile_pic_url_hd) {
const profileUrl = profile.profile_pic_url_hd
const imageBlob = await fetch(profileUrl).then(r => r.blob())
const artworkFile = new File([imageBlob], 'Artwork', {
type: 'image/jpeg'
})
const file = await resizeImage(artworkFile)
const url = URL.createObjectURL(file)
setInstagramProfile(uuid, profile, { url, file })
try {
const profileUrl = profile.profile_pic_url_hd
const imageBlob = await fetch(profileUrl).then(r => r.blob())
const artworkFile = new File([imageBlob], 'Artwork', {
type: 'image/jpeg'
})
const file = await resizeImage(artworkFile)
const url = URL.createObjectURL(file)
setInstagramProfile(uuid, profile, { url, file })
} catch (e) {
console.error('Failed to fetch profile_pic_url_hd', e)
setInstagramProfile(uuid, profile)
}
} else {
setInstagramProfile(uuid, profile)
}
Expand Down

0 comments on commit 2111e13

Please sign in to comment.