Skip to content

Commit

Permalink
feat(packages/graph-client): error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
OlaStenberg committed Aug 7, 2024
1 parent 6d691dc commit f012ebf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ export async function getAnalyticsDayBuckets(
options,
)
if (result) {
return result.sushiDayBuckets
return result.sushiDayBuckets ?? {
v2: [],
v3: [],
}
}
return {
v2: [],
v3: [],
}

throw new Error('No sushi day buckets found')
}

export type AnalyticsDayBuckets = Awaited<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { graphql } from '../../graphql'

export const PoolsQuery = graphql(
`
query Pools($chainId: Int!) {
query TopPools($chainId: Int!) {
topPools(chainId: $chainId) {
chainId
id
chainId
name
address
createdAt
Expand All @@ -30,9 +30,10 @@ query Pools($chainId: Int!) {
feeApr1d
totalApr1d
incentiveApr
source
isIncentivized
isSmartPool
isIncentivized
wasIncentivized
source
}
}
`,
Expand All @@ -54,7 +55,7 @@ export async function getTopPools(
return result.topPools ?? []
}

throw new Error('No pools found')
return []
}

export type TopPools = Awaited<ReturnType<typeof getTopPools>>
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ export async function getV2Pool(
throw new Error('Invalid chainId')
}

try {
const result = await request(
{ url, document: V2PoolQuery, variables },
options,
Expand Down Expand Up @@ -177,12 +176,8 @@ export async function getV2Pool(
PoolWithIncentives<PoolHistory1D<PoolV2<PoolBase>>>
>
}

throw new Error('No pool found')
} catch (_e) {
// console.error(e)
return null
}

}

export type V2Pool = NonNullable<Awaited<ReturnType<typeof getV2Pool>>>
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export async function getV3Pool(
if (!isSushiSwapV3ChainId(chainId)) {
throw new Error('Invalid chainId')
}
try {

const result = await request(
{ url, document: V3PoolQuery, variables },
options,
Expand Down Expand Up @@ -195,11 +195,7 @@ export async function getV3Pool(
>
}

throw new Error('No pool found')
} catch (_e) {
// console.error(e)
return null
}
}

export type MaybeV3Pool = Awaited<ReturnType<typeof getV3Pool>>
Expand Down

0 comments on commit f012ebf

Please sign in to comment.