diff --git a/packages/app/src/cli/services/app-logs/logs-command/ui/components/hooks/usePollAppLogs.test.tsx b/packages/app/src/cli/services/app-logs/logs-command/ui/components/hooks/usePollAppLogs.test.tsx index c120af4746..1568c7bf8c 100644 --- a/packages/app/src/cli/services/app-logs/logs-command/ui/components/hooks/usePollAppLogs.test.tsx +++ b/packages/app/src/cli/services/app-logs/logs-command/ui/components/hooks/usePollAppLogs.test.tsx @@ -374,14 +374,14 @@ describe('usePollAppLogs', () => { // needed to await the render await vi.advanceTimersByTimeAsync(0) - // Initial invocation, 429 returned + // Initial invocation, 422 returned expect(mockedPollAppLogs).toHaveBeenCalledTimes(1) expect(hook.lastResult?.appLogOutputs).toHaveLength(0) expect(hook.lastResult?.errors[0]).toEqual('Error while polling app logs') expect(hook.lastResult?.errors[1]).toEqual('Retrying in 5s') - expect(setTimeout).toHaveBeenCalledWith(expect.any(Function), POLLING_ERROR_RETRY_INTERVAL_MS) + expect(timeoutSpy).toHaveBeenCalledWith(expect.any(Function), POLLING_ERROR_RETRY_INTERVAL_MS) await vi.advanceTimersToNextTimerAsync() expect(hook.lastResult?.appLogOutputs).toHaveLength(6) @@ -391,6 +391,30 @@ describe('usePollAppLogs', () => { expect(vi.getTimerCount()).toEqual(1) timeoutSpy.mockRestore() }) + + test('clears error on success', async () => { + const mockedPollAppLogs = vi + .fn() + .mockResolvedValueOnce(POLL_APP_LOGS_FOR_LOGS_429_RESPONSE) + .mockResolvedValueOnce(POLL_APP_LOGS_FOR_LOGS_RESPONSE) + vi.mocked(pollAppLogs).mockImplementation(mockedPollAppLogs) + + const hook = renderHook(() => + usePollAppLogs({ + initialJwt: MOCKED_JWT_TOKEN, + filters: EMPTY_FILTERS, + resubscribeCallback: vi.fn().mockResolvedValue(MOCKED_JWT_TOKEN), + }), + ) + + // initial poll with errors + await vi.advanceTimersByTimeAsync(0) + expect(hook.lastResult?.errors).toHaveLength(2) + + // second poll with no errors + await vi.advanceTimersToNextTimerAsync() + expect(hook.lastResult?.errors).toHaveLength(0) + }) }) function renderHook(renderHookCallback: () => THookResult) { diff --git a/packages/app/src/cli/services/app-logs/logs-command/ui/components/hooks/usePollAppLogs.ts b/packages/app/src/cli/services/app-logs/logs-command/ui/components/hooks/usePollAppLogs.ts index 0eb6dbff16..3e96aa8a0f 100644 --- a/packages/app/src/cli/services/app-logs/logs-command/ui/components/hooks/usePollAppLogs.ts +++ b/packages/app/src/cli/services/app-logs/logs-command/ui/components/hooks/usePollAppLogs.ts @@ -52,7 +52,7 @@ export function usePollAppLogs({initialJwt, filters, resubscribeCallback}: UsePo } retryIntervalMs = result.retryIntervalMs } else { - setErrors([]) + setErrors((errors) => (errors.length ? [] : errors)) } const {cursor: nextCursor, appLogs} = response as SuccessResponse