Skip to content

Commit

Permalink
chore: handle errors in Bstack run
Browse files Browse the repository at this point in the history
  • Loading branch information
asambstack committed Mar 24, 2023
1 parent ac9c6f8 commit 0d4cfe4
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,22 @@ exports.lighthouse = async ({

let results;
if (process.env.LH_BROWSERSTACK == 'true') {
console.log(`Starting Lighthouse run on Browserstack for url: ${url}`);
console.log(`Starting Lighthouse run on Browserstack for url => ${url}`);
const BSTACK_PARAMS = {
action: 'lighthouse',
arguments: { url: url, lhFlags: opts, lhConfig: config },
};
const response = await page.evaluate((_) => {},
`browserstack_executor: ${JSON.stringify(BSTACK_PARAMS)}`);
const { lhSuccess, data } = JSON.parse(response);
if (lhSuccess == 'false') {
throw new Error(BSTACK_EXECUTION_FAILED + ': ' + JSON.stringify(data));
try {
const { lhSuccess, data } = JSON.parse(response);
results = data;
if (lhSuccess == 'false') throw 'lhRun failed';
} catch (error) {
throw new Error(
BSTACK_EXECUTION_FAILED + ': ' + response
);
}
results = data;
} else {
({ lhr: results } = await lighthouseLib(
url,
Expand Down

0 comments on commit 0d4cfe4

Please sign in to comment.