Skip to content

Commit 0b46a9e

Browse files
committed
fix(gateway api): provide more informative error and logs on GQL errors being returned PE-6152
1 parent 0958c8f commit 0b46a9e

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/types/gql_Types.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,13 @@ export interface GQLTransactionsResultInterface {
7979
export default interface GQLResultInterface {
8080
data: {
8181
transactions: GQLTransactionsResultInterface;
82-
};
82+
} | null;
83+
errors:
84+
| {
85+
message: string;
86+
path: string[];
87+
locations: { line: number; column: number }[];
88+
extensions: { code: string };
89+
}[]
90+
| undefined;
8391
}

src/utils/gateway_api.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ export class GatewayAPI {
8282
try {
8383
const { data } = await this.postToEndpoint<GQLResultInterface>('graphql', query);
8484

85+
if (data.errors) {
86+
data.errors.forEach((error) => {
87+
console.error(`GQL Error: ${error.message}`);
88+
});
89+
}
90+
91+
if (!data.data) {
92+
throw new Error('No data was returned from the GQL request.');
93+
}
94+
8595
return data.data.transactions;
8696
} catch (error) {
8797
throw Error(`GQL Error: ${(error as Error).message}`);

tests/integration/arlocal.int.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ describe('ArLocal Integration Tests', function () {
885885
await arweave.api.post('graphql', buildQuery({ tags: [], owner }))
886886
).data;
887887

888-
const txNode = gqlResp.data.transactions.edges[0].node;
888+
const txNode = gqlResp.data!.transactions.edges[0].node;
889889
return TxID(txNode.id);
890890
}
891891

0 commit comments

Comments
 (0)