Skip to content

Commit e0afbb2

Browse files
handle malformed txs and and not yet present txs
1 parent b3e1aaa commit e0afbb2

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

sdk/src/network-client.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,9 +1218,16 @@ class AleoNetworkClient {
12181218

12191219
if (!res.ok) {
12201220
const text = await res.text();
1221-
console.error("Non-OK response:", res.status, text);
1222-
clearInterval(interval);
1223-
return reject(new Error(`HTTP ${res.status}: ${text}`));
1221+
1222+
// Break early if the response indicates an invalid format
1223+
if (res.status >= 400 && res.status < 500 && text.includes("Invalid URL")) {
1224+
clearInterval(interval);
1225+
return reject(new Error(`Malformed transaction ID: ${text}`));
1226+
}
1227+
1228+
// Log and continue polling for 404s or 5XX errors in case a tx doesn't exist yet
1229+
console.warn("Non-OK response (retrying):", res.status, text);
1230+
return;
12241231
}
12251232

12261233
const data = await res.json();

sdk/tests/network-client.test.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,16 @@ describe('NodeConnection', () => {
211211
expect(status).to.equal("rejected");
212212
});
213213

214-
it('should throw for an invalid tx ID', async () => {
215-
const connection = new AleoNetworkClient("https://api.explorer.provable.com/");
216-
await expectThrows(() =>
217-
connection.waitForTransactionConfirmation("at1dl9lze8wscct0dee8x9tjnfmpj12345678jcnp5f0ywjn5552yrsperzl9")
218-
);
219-
});
214+
it('should throw for a malformed tx ID', async () => {
215+
const connection = new AleoNetworkClient("https://api.explorer.provable.com/");
216+
try {
217+
await connection.waitForTransactionConfirmation("at1dl9lze8wscct0dee8x9tjnfmpj12345678jcnp5f0ywjn5552yrsperzl9");
218+
throw new Error("Expected waitForTransactionConfirmation to throw");
219+
} catch (err: any) {
220+
expect(err.message).to.include("Malformed transaction ID");
221+
expect(err.message).to.include("Invalid URL");
222+
}
223+
});
220224
});
221225

222226
describe('findUnspentRecords', () => {

0 commit comments

Comments
 (0)