Skip to content

Commit

Permalink
Increase timeout to 3s and append error message to log
Browse files Browse the repository at this point in the history
  • Loading branch information
hansott committed Jan 27, 2025
1 parent 689e46d commit 04f6dbd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 6 additions & 2 deletions library/agent/realtime/getConfigLastUpdatedAt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ export async function getConfigLastUpdatedAt(token: Token): Promise<number> {
headers: {
Authorization: token.asString(),
},
timeoutInMS: 500,
timeoutInMS: 3000,
});

if (statusCode === 403) {
throw new Error("Token is invalid");
}

if (statusCode !== 200) {
throw new Error(`Invalid response (${statusCode}): ${body}`);
throw new Error(`Expected status code 200, got ${statusCode}`);
}

const response: RealtimeResponse = JSON.parse(body);
Expand Down
4 changes: 3 additions & 1 deletion library/agent/realtime/pollForChanges.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ t.test("it deals with API throwing errors", async () => {
await clock.nextAsync();

t.same(configUpdates, []);
t.same(logger.getMessages(), ["Failed to check for config updates"]);
t.same(logger.getMessages(), [
`Failed to check for config updates: Request timed out`,
]);

clock.uninstall();
});
4 changes: 2 additions & 2 deletions library/agent/realtime/pollForChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export function pollForChanges({
}

interval = setInterval(() => {
check(token, onConfigUpdate).catch(() => {
logger.log("Failed to check for config updates");
check(token, onConfigUpdate).catch((error) => {
logger.log(`Failed to check for config updates: ${error.message}`);
});
}, 60 * 1000);

Expand Down

0 comments on commit 04f6dbd

Please sign in to comment.