Skip to content

Commit

Permalink
fix(cwv): error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ekremney committed Sep 2, 2024
1 parent 174444d commit 0856649
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/cwv/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,36 @@
import RUMAPIClient from '@adobe/spacecat-shared-rum-api-client';
import { getRUMDomainkey } from '../support/utils.js';
import { AuditBuilder } from '../common/audit-builder.js';
import { hasNonWWWSubdomain } from '../experimentation/handler.js';

const DAILY_THRESHOLD = 1000;
const INTERVAL = 7; // days

export async function CWVRunner(auditUrl, context, site) {
const rumAPIClient = RUMAPIClient.createFrom(context);
const domainkey = await getRUMDomainkey(site.getBaseURL(), context);
const options = {
let options = {
domain: auditUrl,
domainkey,
interval: INTERVAL,
granularity: 'hourly',
};
const cwvData = await rumAPIClient.query('cwv', options);
let cwvData;

try {
cwvData = await rumAPIClient.query('cwv', options);
/* c8 ignore start */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {
if (!hasNonWWWSubdomain(auditUrl) && !auditUrl.toLowerCase().startsWith('www')) {
options = {
...options,
domain: `www.${auditUrl}`,
};
cwvData = await rumAPIClient.query('cwv', options);
}
}
/* c8 ignore stop */
const auditResult = {
cwv: cwvData.filter((data) => data.pageviews >= DAILY_THRESHOLD * INTERVAL),
auditContext: {
Expand Down

0 comments on commit 0856649

Please sign in to comment.