From f012ebfad4f58bebf5c4a46a09d7a4cd29b721a6 Mon Sep 17 00:00:00 2001 From: OlaStenberg Date: Wed, 7 Aug 2024 12:57:07 +0200 Subject: [PATCH] feat(packages/graph-client): error handling --- .../data-api/queries/analytics/day-buckets.ts | 11 ++++++++--- .../src/subgraphs/data-api/queries/pool/top-pools.ts | 11 ++++++----- .../src/subgraphs/data-api/queries/pool/v2-pool.ts | 7 +------ .../src/subgraphs/data-api/queries/pool/v3-pool.ts | 6 +----- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/packages/graph-client/src/subgraphs/data-api/queries/analytics/day-buckets.ts b/packages/graph-client/src/subgraphs/data-api/queries/analytics/day-buckets.ts index 82dacc04eb..96426f7004 100644 --- a/packages/graph-client/src/subgraphs/data-api/queries/analytics/day-buckets.ts +++ b/packages/graph-client/src/subgraphs/data-api/queries/analytics/day-buckets.ts @@ -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< diff --git a/packages/graph-client/src/subgraphs/data-api/queries/pool/top-pools.ts b/packages/graph-client/src/subgraphs/data-api/queries/pool/top-pools.ts index 67c2207262..72603a7d56 100644 --- a/packages/graph-client/src/subgraphs/data-api/queries/pool/top-pools.ts +++ b/packages/graph-client/src/subgraphs/data-api/queries/pool/top-pools.ts @@ -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 @@ -30,9 +30,10 @@ query Pools($chainId: Int!) { feeApr1d totalApr1d incentiveApr - source - isIncentivized isSmartPool + isIncentivized + wasIncentivized + source } } `, @@ -54,7 +55,7 @@ export async function getTopPools( return result.topPools ?? [] } - throw new Error('No pools found') + return [] } export type TopPools = Awaited> diff --git a/packages/graph-client/src/subgraphs/data-api/queries/pool/v2-pool.ts b/packages/graph-client/src/subgraphs/data-api/queries/pool/v2-pool.ts index b24a6e07e4..0786dfe483 100644 --- a/packages/graph-client/src/subgraphs/data-api/queries/pool/v2-pool.ts +++ b/packages/graph-client/src/subgraphs/data-api/queries/pool/v2-pool.ts @@ -98,7 +98,6 @@ export async function getV2Pool( throw new Error('Invalid chainId') } - try { const result = await request( { url, document: V2PoolQuery, variables }, options, @@ -177,12 +176,8 @@ export async function getV2Pool( PoolWithIncentives>> > } - - throw new Error('No pool found') - } catch (_e) { - // console.error(e) return null - } + } export type V2Pool = NonNullable>> diff --git a/packages/graph-client/src/subgraphs/data-api/queries/pool/v3-pool.ts b/packages/graph-client/src/subgraphs/data-api/queries/pool/v3-pool.ts index 9778c434d7..00ff507d98 100644 --- a/packages/graph-client/src/subgraphs/data-api/queries/pool/v3-pool.ts +++ b/packages/graph-client/src/subgraphs/data-api/queries/pool/v3-pool.ts @@ -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, @@ -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>