Skip to content

Commit

Permalink
fix: log ahrefs url
Browse files Browse the repository at this point in the history
  • Loading branch information
dzehnder committed Jan 30, 2024
1 parent adaeb19 commit 55bfef9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/backlinks/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default async function auditBrokenBacklinks(message, context) {
const {
result,
fullAuditRef,
} = await ahrefsAPIClient.getBrokenBacklinks(url);
} = await ahrefsAPIClient.getBrokenBacklinks(url, log);

log.info(`Found ${result?.backlinks?.length} broken backlinks for siteId: ${siteId} and url ${url}`);

Expand Down
9 changes: 5 additions & 4 deletions src/support/ahrefs-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ export default class AhrefsAPIClient {
this.apiKey = apiKey;
}

async sendRequest(endpoint, queryParams = {}) {
async sendRequest(endpoint, log, queryParams = {}) {
const queryParamsKeys = Object.keys(queryParams);
const queryString = queryParamsKeys.length > 0
? `?${queryParamsKeys
.map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(queryParams[key])}`)
.join('&')}` : '';

const fullAuditRef = `${this.apiBaseUrl}${endpoint}${queryString}`;
log?.info(`AuditRef: ${fullAuditRef}`);
const response = await fetch(fullAuditRef, {
method: 'GET',
headers: {
Expand All @@ -62,7 +63,7 @@ export default class AhrefsAPIClient {
}
}

async getBrokenBacklinks(url) {
async getBrokenBacklinks(url, log) {
const filter = {
and: [
{ field: 'is_dofollow', is: ['eq', 1] },
Expand All @@ -87,7 +88,7 @@ export default class AhrefsAPIClient {
where: JSON.stringify(filter),
};

return this.sendRequest('/site-explorer/broken-backlinks', queryParams);
return this.sendRequest('/site-explorer/broken-backlinks', log, queryParams);
}

async getOrganicKeywords(site, log) {
Expand Down Expand Up @@ -128,6 +129,6 @@ export default class AhrefsAPIClient {

log.info(`Sending request to Ahrefs API with query params: ${JSON.stringify(queryParams)}}`);

return this.sendRequest('/site-explorer/organic-keywords', queryParams);
return this.sendRequest('/site-explorer/organic-keywords', log, queryParams);
}
}

0 comments on commit 55bfef9

Please sign in to comment.