Skip to content

Commit

Permalink
chore(connect): add log and error handle if querying the gateway fails
Browse files Browse the repository at this point in the history
  • Loading branch information
TillaTheHun0 committed Mar 26, 2024
1 parent 43b6462 commit a81d791
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
8 changes: 6 additions & 2 deletions connect/src/client/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { z } from 'zod'
* @param {Env1} env
* @returns {LoadTransactionMeta}
*/
export function loadTransactionMetaWith ({ fetch, GRAPHQL_URL }) {
export function loadTransactionMetaWith ({ fetch, GRAPHQL_URL, logger }) {
// TODO: create a dataloader and use that to batch load contracts

const GET_TRANSACTIONS_QUERY = `
Expand Down Expand Up @@ -60,7 +60,11 @@ export function loadTransactionMetaWith ({ fetch, GRAPHQL_URL }) {
variables: { transactionIds: [id] }
})
})
.then((res) => res.json())
.then(async (res) => {
if (res.ok) return res.json()
logger('Error Encountered when querying gateway for transaction "%s"', id)
throw new Error(`${res.status}: ${await res.text()}`)
})
.then(transactionConnectionSchema.parse)
.then(path(['data', 'transactions', 'edges', '0', 'node']))
))
Expand Down
9 changes: 7 additions & 2 deletions connect/src/client/gateway.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { describe, test } from 'node:test'
import * as assert from 'node:assert'

import { createLogger } from '../logger.js'
import { loadTransactionMetaSchema } from '../dal.js'
import { loadTransactionMetaWith } from './gateway.js'

const logger = createLogger('ao-cu')

const GRAPHQL_URL = globalThis.GRAPHQL_URL || 'https://arweave.net/graphql'
const PROCESS = 'zc24Wpv_i6NNCEdxeKt7dcNrqL5w0hrShtSCcFGGL24'

Expand All @@ -13,7 +16,8 @@ describe('gateway', () => {
const loadTransactionMeta = loadTransactionMetaSchema.implement(
loadTransactionMetaWith({
fetch,
GRAPHQL_URL
GRAPHQL_URL,
logger
})
)
const result = await loadTransactionMeta(PROCESS)
Expand Down Expand Up @@ -54,7 +58,8 @@ describe('gateway', () => {
}

return new Response(JSON.stringify({ byteLength: 214390 }))
}
},
logger
}))

await loadTransactionMeta(PROCESS)
Expand Down
2 changes: 1 addition & 1 deletion connect/src/index.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export function connect ({
*/
const spawnLogger = logger.child('spawn')
const spawn = spawnWith({
loadTransactionMeta: GatewayClient.loadTransactionMetaWith({ fetch, GATEWAY_URL }),
loadTransactionMeta: GatewayClient.loadTransactionMetaWith({ fetch, GATEWAY_URL, logger: spawnLogger }),
validateScheduler: validate,
deployProcess: MuClient.deployProcessWith({ fetch, MU_URL, logger: spawnLogger }),
logger: spawnLogger
Expand Down

0 comments on commit a81d791

Please sign in to comment.