mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
more proper error throwing
This commit is contained in:
parent
8edd3a4f60
commit
7f104c9858
@ -119,11 +119,11 @@ export default function Compute({
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function initPriceAndFees() {
|
async function initPriceAndFees() {
|
||||||
|
try {
|
||||||
const computeEnv = await getComputeEnviroment(asset)
|
const computeEnv = await getComputeEnviroment(asset)
|
||||||
if (!computeEnv || !computeEnv.id) {
|
if (!computeEnv || !computeEnv.id)
|
||||||
setError(`Error getting compute environments!`)
|
throw new Error(`Error getting compute environments!`)
|
||||||
return
|
|
||||||
}
|
|
||||||
setComputeEnv(computeEnv)
|
setComputeEnv(computeEnv)
|
||||||
const initializedProvider = await initializeProviderForCompute(
|
const initializedProvider = await initializeProviderForCompute(
|
||||||
asset,
|
asset,
|
||||||
@ -135,10 +135,9 @@ export default function Compute({
|
|||||||
!initializedProvider ||
|
!initializedProvider ||
|
||||||
!initializedProvider?.datasets ||
|
!initializedProvider?.datasets ||
|
||||||
!initializedProvider?.algorithm
|
!initializedProvider?.algorithm
|
||||||
) {
|
)
|
||||||
setError(`Error initializing provider for the compute job!`)
|
throw new Error(`Error initializing provider for the compute job!`)
|
||||||
return
|
|
||||||
}
|
|
||||||
setInitializedProviderResponse(initializedProvider)
|
setInitializedProviderResponse(initializedProvider)
|
||||||
setProviderFeeAmount(
|
setProviderFeeAmount(
|
||||||
await unitsToAmount(
|
await unitsToAmount(
|
||||||
@ -152,6 +151,7 @@ export default function Compute({
|
|||||||
Math.floor(Date.now() / 1000)
|
Math.floor(Date.now() / 1000)
|
||||||
).toString()
|
).toString()
|
||||||
setComputeValidUntil(computeDuration)
|
setComputeValidUntil(computeDuration)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
asset?.accessDetails?.addressOrId !== ZERO_ADDRESS &&
|
asset?.accessDetails?.addressOrId !== ZERO_ADDRESS &&
|
||||||
asset?.accessDetails?.type !== 'free' &&
|
asset?.accessDetails?.type !== 'free' &&
|
||||||
@ -186,10 +186,9 @@ export default function Compute({
|
|||||||
poolParams,
|
poolParams,
|
||||||
initializedProvider?.datasets?.[0]?.providerFee
|
initializedProvider?.datasets?.[0]?.providerFee
|
||||||
)
|
)
|
||||||
if (!datasetPriceAndFees) {
|
if (!datasetPriceAndFees)
|
||||||
setError('Error setting dataset price and fees!')
|
throw new Error('Error setting dataset price and fees!')
|
||||||
return
|
|
||||||
}
|
|
||||||
setDatasetOrderPriceAndFees(datasetPriceAndFees)
|
setDatasetOrderPriceAndFees(datasetPriceAndFees)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,12 +232,15 @@ export default function Compute({
|
|||||||
algoPoolParams,
|
algoPoolParams,
|
||||||
initializedProvider.algorithm.providerFee
|
initializedProvider.algorithm.providerFee
|
||||||
)
|
)
|
||||||
if (!algorithmOrderPriceAndFees) {
|
if (!algorithmOrderPriceAndFees)
|
||||||
setError('Error setting algorithm price and fees!')
|
throw new Error('Error setting algorithm price and fees!')
|
||||||
return
|
|
||||||
}
|
|
||||||
setAlgoOrderPriceAndFees(algorithmOrderPriceAndFees)
|
setAlgoOrderPriceAndFees(algorithmOrderPriceAndFees)
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
setError(error.message)
|
||||||
|
LoggerInstance.error(`[compute] ${error.message} `)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -287,7 +289,7 @@ export default function Compute({
|
|||||||
toast.error(newError)
|
toast.error(newError)
|
||||||
}, [error])
|
}, [error])
|
||||||
|
|
||||||
async function startJob(): Promise<string> {
|
async function startJob(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
setIsOrdering(true)
|
setIsOrdering(true)
|
||||||
setIsOrdered(false)
|
setIsOrdered(false)
|
||||||
@ -304,15 +306,10 @@ export default function Compute({
|
|||||||
selectedAlgorithmAsset
|
selectedAlgorithmAsset
|
||||||
)
|
)
|
||||||
LoggerInstance.log('[compute] Is data set orderable?', allowed)
|
LoggerInstance.log('[compute] Is data set orderable?', allowed)
|
||||||
if (!allowed) {
|
if (!allowed)
|
||||||
setError(
|
throw new Error(
|
||||||
'Data set is not orderable in combination with selected algorithm.'
|
'Data set is not orderable in combination with selected algorithm.'
|
||||||
)
|
)
|
||||||
LoggerInstance.error(
|
|
||||||
'[compute] Error starting compute job. Dataset is not orderable in combination with selected algorithm.'
|
|
||||||
)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
setComputeStatusText(
|
setComputeStatusText(
|
||||||
getComputeFeedback(
|
getComputeFeedback(
|
||||||
@ -336,11 +333,8 @@ export default function Compute({
|
|||||||
initializedProviderResponse.datasets[0],
|
initializedProviderResponse.datasets[0],
|
||||||
computeEnv.consumerAddress
|
computeEnv.consumerAddress
|
||||||
)
|
)
|
||||||
if (!datasetOrderTx) {
|
if (!datasetOrderTx) throw new Error('Failed to order dataset.')
|
||||||
setError('Failed to order dataset.')
|
|
||||||
LoggerInstance.error('[compute] Failed to order dataset.')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
setComputeStatusText(
|
setComputeStatusText(
|
||||||
getComputeFeedback(
|
getComputeFeedback(
|
||||||
selectedAlgorithmAsset.accessDetails.baseToken?.symbol,
|
selectedAlgorithmAsset.accessDetails.baseToken?.symbol,
|
||||||
@ -364,11 +358,7 @@ export default function Compute({
|
|||||||
initializedProviderResponse.algorithm,
|
initializedProviderResponse.algorithm,
|
||||||
computeEnv.consumerAddress
|
computeEnv.consumerAddress
|
||||||
)
|
)
|
||||||
if (!algorithmOrderTx) {
|
if (!algorithmOrderTx) throw new Error('Failed to order algorithm.')
|
||||||
setError('Failed to order algorithm.')
|
|
||||||
LoggerInstance.error('[compute] Failed to order algorithm.')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
LoggerInstance.log('[compute] Starting compute job.')
|
LoggerInstance.log('[compute] Starting compute job.')
|
||||||
const computeAsset: ComputeAsset = {
|
const computeAsset: ComputeAsset = {
|
||||||
@ -393,17 +383,15 @@ export default function Compute({
|
|||||||
null,
|
null,
|
||||||
output
|
output
|
||||||
)
|
)
|
||||||
if (!response) {
|
if (!response) throw new Error('Error starting compute job.')
|
||||||
setError('Error starting compute job.')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
LoggerInstance.log('[compute] Starting compute job response: ', response)
|
LoggerInstance.log('[compute] Starting compute job response: ', response)
|
||||||
setIsOrdered(true)
|
setIsOrdered(true)
|
||||||
setRefetchJobs(!refetchJobs)
|
setRefetchJobs(!refetchJobs)
|
||||||
initPriceAndFees()
|
initPriceAndFees()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setError('Failed to start job!')
|
setError(error.message)
|
||||||
LoggerInstance.error('[compute] Failed to start job: ', error.message)
|
LoggerInstance.error(`[compute] ${error.message} `)
|
||||||
} finally {
|
} finally {
|
||||||
setIsOrdering(false)
|
setIsOrdering(false)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user