Commit dbbffd17 authored by Moody Salem's avatar Moody Salem

fix: improve cancel/retry detection

parent 85d8b1e5
......@@ -5,7 +5,7 @@ import { useActiveWeb3React } from '../../hooks/web3'
import { useMulticall2Contract } from '../../hooks/useContract'
import useDebounce from '../../hooks/useDebounce'
import chunkArray from '../../utils/chunkArray'
import { CancelledError, retry, RetryableError } from '../../utils/retry'
import { retry, RetryableError } from '../../utils/retry'
import { useBlockNumber } from '../application/hooks'
import { AppDispatch, AppState } from '../index'
import {
......@@ -217,7 +217,7 @@ export default function Updater(): null {
}
})
.catch((error: any) => {
if (error instanceof CancelledError) {
if (error.isCancelledError) {
console.debug('Cancelled fetch for blockNumber', latestBlockNumber)
return
}
......
......@@ -10,6 +10,7 @@ function waitRandom(min: number, max: number): Promise<void> {
* This error is thrown if the function is cancelled before completing
*/
export class CancelledError extends Error {
public isCancelledError: true = true
constructor() {
super('Cancelled')
}
......@@ -18,7 +19,9 @@ export class CancelledError extends Error {
/**
* Throw this error if the function should retry
*/
export class RetryableError extends Error {}
export class RetryableError extends Error {
public isRetryableError: true = true
}
/**
* Retries the function that returns the promise until the promise successfully resolves up to n retries
......@@ -48,7 +51,7 @@ export function retry<T>(
if (completed) {
break
}
if (n <= 0 || !(error instanceof RetryableError)) {
if (n <= 0 || !error.isRetryableError) {
reject(error)
completed = true
break
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment