Skip to content

Commit

Permalink
Handle rest leftout axios error
Browse files Browse the repository at this point in the history
  • Loading branch information
WRadoslaw committed Aug 14, 2023
1 parent 8bd2382 commit 6b01314
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { ContextMenu } from '@/components/_overlays/ContextMenu'
import { atlasConfig } from '@/config'
import { useGetAssetUrl } from '@/hooks/useGetAssetUrl'
import { useConfirmationModal } from '@/providers/confirmationModal'
import { useSnackbar } from '@/providers/snackbars'
import { SubtitlesInput } from '@/types/subtitles'
import { SentryLogger } from '@/utils/logs'

import {
InvisibleInput,
Expand Down Expand Up @@ -39,21 +41,30 @@ export const SubtitlesBox: FC<SubtitleBoxProps> = ({
}) => {
const inputRef = useRef<HTMLInputElement>(null)
const [openUnsuportedFileDialog, closeUnsuportedFileDialog] = useConfirmationModal()
const { displaySnackbar } = useSnackbar()
const hasFile = !!file || !!id
const { mutateAsync: subtitlesFetch } = useMutation('subtitles-fetch', (url: string) =>
axiosInstance.get(url, { responseType: 'blob' })
)
const { url } = useGetAssetUrl(asset?.resolvedUrls, 'subtitle')

const handleDownload = async (url = '') => {
const response = await subtitlesFetch(url)
const objectURL = window.URL.createObjectURL(new Blob([response.data]))
const link = document.createElement('a')
link.href = objectURL
link.setAttribute('download', `${id}-${languageIso.toLowerCase()}.vtt`)
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
try {
const response = await subtitlesFetch(url)
const objectURL = window.URL.createObjectURL(new Blob([response.data]))
const link = document.createElement('a')
link.href = objectURL
link.setAttribute('download', `${id}-${languageIso.toLowerCase()}.vtt`)
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
} catch (error) {
SentryLogger.error('Failed to fetch subtitles for download', 'handleDownload', error)
displaySnackbar({
title: 'Failed to connect to distributor',
iconType: 'error',
})
}
}

const contexMenuItems: ListItemProps[] = [
Expand Down
12 changes: 7 additions & 5 deletions packages/atlas/src/providers/assets/assets.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ export const logDistributorPerformance = async (assetUrl: string, eventEntry: Di

export const getFastestImageUrl = async (urls: string[]) => {
const promises = urls.map((url) => {
return axiosInstance.head(url, {
headers: {
'Cache-Control': 'no-cache',
},
})
return axiosInstance
.head(url, {
headers: {
'Cache-Control': 'no-cache',
},
})
.catch((error) => ConsoleLogger.warn('Failed while performing performance download', error))
})
return Promise.race(promises)
}
7 changes: 3 additions & 4 deletions packages/atlas/src/providers/auth/auth.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { atlasConfig } from '@/config'
import { ORION_AUTH_URL } from '@/config/env'
import { keyring } from '@/joystream-lib/lib'
import { getWalletsList } from '@/providers/wallet/wallet.helpers'
import { SentryLogger } from '@/utils/logs'
import { ConsoleLogger, SentryLogger } from '@/utils/logs'
import { withTimeout } from '@/utils/misc'

import { AuthModals, LogInErrors, OrionAccountError, RegisterParams, RegisterPayload } from './auth.types'
Expand Down Expand Up @@ -104,7 +104,7 @@ export const decodeSessionEncodedSeedToMnemonic = async (encodedSeed: string) =>
return _entropyToMnemonic(Buffer.from(decryptedSeed.slice(2, decryptedSeed.length), 'hex'))
} catch (e) {
if (isAxiosError(e) && e.response?.data.message === 'isAxiosError') {
logoutRequest()
logoutRequest().catch((error) => ConsoleLogger.warn('Failed to logout on decoding error', error))
}
return null
}
Expand Down Expand Up @@ -269,8 +269,7 @@ export const getMnemonicFromeEmailAndPassword = async (email: string, password:
if (!data?.decryptedEntropy) {
throw Error("Couldn't fetch artifacts")
}
const mnemonic = entropyToMnemonic(data?.decryptedEntropy)
return mnemonic
return entropyToMnemonic(data?.decryptedEntropy)
}

export const getAuthEpoch = async () => {
Expand Down

0 comments on commit 6b01314

Please sign in to comment.