Skip to content

Commit 10eee3b

Browse files
committed
changes to handle timeout
1 parent 5cea50f commit 10eee3b

File tree

3 files changed

+8
-23
lines changed

3 files changed

+8
-23
lines changed

packages/sdk-utils/src/lib/httpClient.js

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,6 @@ module.exports = new class httpClient {
1313
};
1414
})
1515
.catch(error => {
16-
if (error.code === 'ECONNABORTED') {
17-
// Custom response for timeout on /snapshot/status
18-
if (config.url.includes('/snapshot/status')) {
19-
return {
20-
status: 408,
21-
statusMessage: 'Request Timeout',
22-
body: `Request timed out after ${config.timeout / 1000} seconds-> Snapshot still processing`
23-
};
24-
}
25-
return {
26-
status: 408,
27-
statusMessage: 'Request Timeout',
28-
body: `Request timed out after ${config.timeout / 1000} seconds`
29-
};
30-
}
3116
if (error.response) {
3217
throw new Error(error.response.data.error.message);
3318
}
@@ -63,14 +48,15 @@ module.exports = new class httpClient {
6348
})
6449
}
6550

66-
getSnapshotStatus(contextId, timeout = 600) {
51+
getSnapshotStatus(contextId, snapshotName, pollTimeout) {
6752
return this.request({
6853
url: `${utils.getSmartUIServerAddress()}/snapshot/status`,
6954
method: 'GET',
7055
params: {
71-
contextId: contextId
72-
},
73-
timeout: timeout * 1000 // Convert timeout from seconds to milliseconds
56+
contextId: contextId,
57+
snapshotName: snapshotName,
58+
pollTimeout: pollTimeout
59+
}
7460
});
7561
}
7662

packages/sdk-utils/src/smartui.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ async function postSnapshot(snapshot, testType) {
3636
}
3737
}
3838

39-
async function getSnapshotStatus(contextId,timeout=600) {
39+
async function getSnapshotStatus(contextId,snapshotName,pollTimeout=600) {
4040
try {
41-
return await client.getSnapshotStatus(contextId,timeout);
41+
return await client.getSnapshotStatus(contextId,snapshotName,pollTimeout);
4242
} catch (error) {
4343
log.debug(error);
4444
throw new Error(`get snapshot status failed; ${error.message}`);

packages/selenium/src/smartui.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ async function smartuiSnapshot(driver, name, options = {}) {
3131
let { body } = await utils.postSnapshot({url, name, dom, options}, pkgName);
3232
if (body && body.data && body.data.warnings?.length !== 0) body.data.warnings.map(e => log.warn(e));
3333
log.info(`Snapshot captured: ${name}`);
34-
let timeout = options?.timeout || 600;
35-
let snapshotStatus = await utils.getSnapshotStatus(options.contextId,timeout);
34+
let snapshotStatus = await utils.getSnapshotStatus(options.contextId,name,options?.timeout);
3635
return snapshotStatus.body;
3736
}
3837
else{

0 commit comments

Comments
 (0)