Skip to content

Commit 9d49d89

Browse files
committed
added timeout option for get snapshot status
1 parent 57e6b79 commit 9d49d89

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ 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+
}
1631
if (error.response) {
1732
throw new Error(error.response.data.error.message);
1833
}
@@ -48,13 +63,15 @@ module.exports = new class httpClient {
4863
})
4964
}
5065

51-
getSnapshotStatus(contextId) {
66+
getSnapshotStatus(contextId, timeout = 600) {
5267
return this.request({
5368
url: `${utils.getSmartUIServerAddress()}/snapshot/status`,
5469
method: 'GET',
5570
params: {
5671
contextId: contextId
57-
}
58-
})
72+
},
73+
timeout: timeout * 1000 // Convert timeout from seconds to milliseconds
74+
});
5975
}
76+
6077
};

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

packages/selenium/src/smartui.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,9 @@ async function smartuiSnapshot(driver, name, options = {}) {
3333
let { body } = await utils.postSnapshot({url, name, dom, options}, pkgName);
3434
if (body && body.data && body.data.warnings?.length !== 0) body.data.warnings.map(e => log.warn(e));
3535
log.info(`Snapshot captured: ${name}`);
36-
let snapshotStatus = await utils.getSnapshotStatus(options.contextId);
37-
console.log("snapshotStatus----->",snapshotStatus);
38-
console.log("snapshotStatus.body----->",snapshotStatus.body);
39-
console.log("snapshotStatus.body.data----->",snapshotStatus.body?.data);
40-
// if(snapshotStatus.body?.data?.status === "success"){
41-
// console.log("Snapshot completed: ",name);
42-
// }
43-
// else{
44-
// console.log(`Snapshot in progress: ${name}`);
45-
// }
36+
let timeout = options?.timeout || 600;
37+
let snapshotStatus = await utils.getSnapshotStatus(options.contextId,timeout);
38+
return snapshotStatus.body;
4639
}
4740
else{
4841
let { body } = await utils.postSnapshot({url, name, dom, options}, pkgName);

0 commit comments

Comments
 (0)