Skip to content

Commit

Permalink
fix: rescue subgraph query errors from snapshot.js
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e committed Aug 26, 2023
1 parent 17d93e6 commit 9a99067
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
35 changes: 23 additions & 12 deletions src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export async function getSubscribers(space) {
try {
const result = await snapshot.utils.subgraphRequest(`${HUB_URL}/graphql`, query);
subscriptions = result.subscriptions || [];
} catch (error) {
capture(error);
} catch (e: any) {
capture(e, { contexts: { input: { query, space } } });
}
return subscriptions.map(subscription => subscription.address);
}
Expand Down Expand Up @@ -55,12 +55,18 @@ export async function getProposal(id) {
snapshot: true
}
};
const result = await snapshot.utils.subgraphRequest(`${HUB_URL}/graphql`, query);
if (result.errors) {
throw new Error(`[events] Errors in subgraph request for proposal id: ${id}`);

try {
const result = await snapshot.utils.subgraphRequest(`${HUB_URL}/graphql`, query);
if (result.errors) {
console.error(`[events] Errors in subgraph request for proposal id: ${id}`);
}
proposal = result.proposal || null;
return proposal;
} catch (e: any) {
capture(e, { contexts: { input: { query, id } } });
return null;
}
proposal = result.proposal || null;
return proposal;
}

export async function getSpace(id) {
Expand All @@ -74,10 +80,15 @@ export async function getSpace(id) {
name: true
}
};
const result = await snapshot.utils.subgraphRequest(`${HUB_URL}/graphql`, query);
if (result.errors) {
throw new Error(`[events] Errors in subgraph request for proposal id: ${id}`);
try {
const result = await snapshot.utils.subgraphRequest(`${HUB_URL}/graphql`, query);
if (result.errors) {
console.error(`[events] Errors in subgraph request for proposal id: ${id}`);
}
space = result.space || null;
return space;
} catch (e: any) {
capture(e, { contexts: { input: { query, id } } });
return null;
}
space = result.space || null;
return space;
}
4 changes: 2 additions & 2 deletions src/replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ async function getNextMessages(mci: number) {
try {
const results = await snapshot.utils.subgraphRequest(`${hubURL}/graphql`, query);
return results.messages;
} catch (e) {
capture(e);
} catch (e: any) {
capture(e, { contexts: { input: { query, mci } } });
console.log('Failed to load messages', e);
return;
}
Expand Down

0 comments on commit 9a99067

Please sign in to comment.