mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
Throwing an error if the provider is not available (#1865)
* Throwing an error if the provider is not available * Adding jest moch for checking if the provider is valid * Removing console log
This commit is contained in:
parent
961a688f27
commit
b9329a1456
@ -147,3 +147,14 @@ export async function downloadFile(
|
||||
)
|
||||
await downloadFileBrowser(downloadUrl)
|
||||
}
|
||||
|
||||
export async function checkValidProvider(
|
||||
providerUrl: string
|
||||
): Promise<boolean> {
|
||||
try {
|
||||
const response = await ProviderInstance.isValidProvider(providerUrl)
|
||||
return response
|
||||
} catch (error) {
|
||||
LoggerInstance.error(error.message)
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ import { fireEvent, render, screen } from '@testing-library/react'
|
||||
import React from 'react'
|
||||
import FilesInput from './index'
|
||||
import { useField } from 'formik'
|
||||
import { getFileInfo } from '@utils/provider'
|
||||
import { getFileInfo, checkValidProvider } from '@utils/provider'
|
||||
|
||||
jest.mock('formik')
|
||||
jest.mock('@utils/provider')
|
||||
@ -48,6 +48,7 @@ const mockForm = {
|
||||
describe('@shared/FormInput/InputElement/FilesInput', () => {
|
||||
it('renders without crashing', async () => {
|
||||
;(useField as jest.Mock).mockReturnValue([mockField, mockMeta, mockHelpers])
|
||||
;(checkValidProvider as jest.Mock).mockReturnValue(true)
|
||||
;(getFileInfo as jest.Mock).mockReturnValue([
|
||||
{
|
||||
valid: true,
|
||||
|
@ -3,7 +3,7 @@ import { useField } from 'formik'
|
||||
import FileInfo from './Info'
|
||||
import UrlInput from '../URLInput'
|
||||
import { InputProps } from '@shared/FormInput'
|
||||
import { getFileInfo } from '@utils/provider'
|
||||
import { getFileInfo, checkValidProvider } from '@utils/provider'
|
||||
import { LoggerInstance } from '@oceanprotocol/lib'
|
||||
import { useAsset } from '@context/Asset'
|
||||
import { isGoogleUrl } from '@utils/url/index'
|
||||
@ -33,6 +33,13 @@ export default function FilesInput(props: InputProps): ReactElement {
|
||||
)
|
||||
}
|
||||
|
||||
// Check if provider is a valid provider
|
||||
const isValid = await checkValidProvider(providerUrl)
|
||||
if (!isValid)
|
||||
throw Error(
|
||||
'✗ Provider cannot be reached, please check status.oceanprotocol.com and try again later.'
|
||||
)
|
||||
|
||||
const checkedFile = await getFileInfo(url, providerUrl, storageType)
|
||||
|
||||
// error if something's not right from response
|
||||
|
Loading…
Reference in New Issue
Block a user