Skip to content

Commit

Permalink
fix: handle errors thrown in subgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
chrstnmcf committed Sep 13, 2024
1 parent 552755e commit a78dae0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,14 @@ async function makeGraphqlRequest ({ server, headers, query }) {
query
})

const { data, errors } = await gqlResponse.body.json()
const res = await gqlResponse.body.json()
// check if exception was thrown by the subgraph
if (res.error) {
const msg = res.message ?? res.error ?? 'Unknown subgraph request error'
throw new Error(msg, { cause: res })
}

const { data, errors } = res
if (errors) {
const msg = errors?.[0]?.message ?? 'Unknown subgraph request error'
throw new Error(msg, { cause: errors })
Expand Down

0 comments on commit a78dae0

Please sign in to comment.