Commit e5b779f6 authored by Moody Salem's avatar Moody Salem

Fix reliability of error checking

parent dcd2fccf
......@@ -8,7 +8,6 @@ import { Price } from './fractions/price'
import { Percent } from './fractions/percent'
import { Token } from 'entities/token'
import { sortedInsert } from '../utils'
import { InsufficientReservesError, InsufficientInputAmountError } from '../errors'
function getSlippage(midPrice: Price, inputAmount: TokenAmount, outputAmount: TokenAmount): Percent {
const exactQuote = midPrice.raw.multiply(inputAmount.raw)
......@@ -143,7 +142,8 @@ export class Trade {
try {
;[amountOut] = pair.getOutputAmount(amountIn)
} catch (error) {
if (error instanceof InsufficientInputAmountError) {
// input too low
if (error.isInsufficientInputAmountError) {
continue
}
throw error
......@@ -211,7 +211,7 @@ export class Trade {
;[amountIn] = pair.getInputAmount(amountOut)
} catch (error) {
// not enough liquidity in this pair
if (error instanceof InsufficientReservesError) {
if (error.isInsufficientReservesError) {
continue
}
throw error
......
......@@ -2,6 +2,8 @@
const CAN_SET_PROTOTYPE = 'setPrototypeOf' in Object
export class InsufficientReservesError extends Error {
public readonly isInsufficientReservesError: true = true
public constructor() {
super()
this.name = this.constructor.name
......@@ -10,6 +12,8 @@ export class InsufficientReservesError extends Error {
}
export class InsufficientInputAmountError extends Error {
public readonly isInsufficientInputAmountError: true = true
public constructor() {
super()
this.name = this.constructor.name
......
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