Skip to content

Commit ec5604b

Browse files
CopilotNitayRabi
andauthored
fix: make transient fallback matching case-insensitive
Agent-Logs-Url: https://github.com/code-rabi/interactive-brokers-mcp/sessions/125deb3a-4a4b-45a5-b3bb-4056d35a0543 Co-authored-by: NitayRabi <24541325+NitayRabi@users.noreply.github.com>
1 parent 34df256 commit ec5604b

2 files changed

Lines changed: 39 additions & 5 deletions

File tree

src/flex-query-client.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,12 @@ export class FlexQueryClient {
198198

199199
if (statementResponse.error) {
200200
const code = statementResponse.errorCode ?? "";
201+
const normalizedError = statementResponse.error.toLowerCase();
201202
const isTransient =
202203
FlexQueryClient.TRANSIENT_GET_STATEMENT_ERROR_CODES.has(code) ||
203-
statementResponse.error.includes("in progress") ||
204-
statementResponse.error.includes("not ready") ||
205-
statementResponse.error.includes("try again");
204+
normalizedError.includes("in progress") ||
205+
normalizedError.includes("not ready") ||
206+
normalizedError.includes("try again");
206207

207208
if (isTransient) {
208209
Logger.log(
@@ -245,4 +246,3 @@ export class FlexQueryClient {
245246
}
246247

247248

248-

test/flex-query-client.test.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,41 @@ describe('FlexQueryClient', () => {
340340
expect(mockGet).toHaveBeenCalledTimes(2);
341341
});
342342

343+
it('should retry when fallback transient message casing differs', async () => {
344+
const sendResponseXml = `<?xml version="1.0" encoding="UTF-8"?>
345+
<FlexStatementResponse timestamp="26 August, 2023 01:59 PM EDT">
346+
<Status>Success</Status>
347+
<ReferenceCode>${mockReferenceCode}</ReferenceCode>
348+
</FlexStatementResponse>`;
349+
350+
const transientXml = `<?xml version="1.0" encoding="UTF-8"?>
351+
<FlexStatementResponse timestamp="26 August, 2023 02:00 PM EDT">
352+
<Status>Fail</Status>
353+
<ErrorCode>9999</ErrorCode>
354+
<ErrorMessage>Statement could not be retrieved. Try Again Shortly.</ErrorMessage>
355+
</FlexStatementResponse>`;
356+
357+
const statementXml = `<?xml version="1.0" encoding="UTF-8"?>
358+
<FlexQueryResponse queryName="Test Query" type="AF">
359+
<FlexStatements count="1">
360+
<FlexStatement accountId="U12345" />
361+
</FlexStatements>
362+
</FlexQueryResponse>`;
363+
364+
const mockGet = vi.fn()
365+
.mockResolvedValueOnce({ data: sendResponseXml })
366+
.mockResolvedValueOnce({ data: transientXml })
367+
.mockResolvedValueOnce({ data: statementXml });
368+
369+
(axios.create as any).mockReturnValue({ get: mockGet });
370+
client = new FlexQueryClient({ token: mockToken });
371+
372+
const result = await client.executeQuery(mockQueryId, 3, 10);
373+
374+
expect(result).toEqual({ data: statementXml });
375+
expect(mockGet).toHaveBeenCalledTimes(3);
376+
});
377+
343378
it('should return error when sendRequest fails', async () => {
344379
const sendResponseXml = `<?xml version="1.0" encoding="UTF-8"?>
345380
<FlexStatementResponse timestamp="26 August, 2023 01:59 PM EDT">
@@ -446,4 +481,3 @@ describe('FlexQueryClient', () => {
446481
});
447482
});
448483
});
449-

0 commit comments

Comments
 (0)