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