Skip to content

Commit

Permalink
add more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Bodin committed Sep 27, 2020
1 parent 76ebd3d commit a38621b
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,16 @@ export async function onSuccess(params: BuildParams): Promise<void> {
algoliaBaseUrl === ''
) {
return utils.build.failBuild(
'Missing ALGOLIA_API_KEY or ALGOLIA_BASE_URL, please go to https://crawler.algolia.com/admin/netlify to complete installation.'
'Missing ALGOLIA_API_KEY or ALGOLIA_BASE_URL, please go to https://crawler.algolia.com/admin/netlify to complete your installation.'
);
}

const endpoint = `${algoliaBaseUrl}/api/1/netlify/crawl`;
const creds = `${siteId}:${algoliaApiKey}`;

try {
console.log('Sending request to crawl', endpoint);

const response = await fetch(endpoint, {
method: 'POST',
headers: {
Expand All @@ -81,13 +83,20 @@ export async function onSuccess(params: BuildParams): Promise<void> {
`${response.statusText} ${JSON.stringify(response.json())}`
);
}
const json: { crawlerId: string } = await response.json();

console.log(
'Crawler done got response',
`API answered: ${response.status}`,
JSON.stringify(json)
);

utils.status.show({
title: 'Crawling...',
summary: `API answered: ${response.status}`,
text: await response.text(),
title: 'Algolia Crawler',
summary: `Your crawler is running at: ${algoliaBaseUrl}/admin/user_configs/${json.crawlerId}`,
});
} catch (error) {
console.error('Could not reach algolia', error);
utils.build.failBuild(
`Could not reach Algolia's Crawler, got: ${error.message}`
);
Expand Down

0 comments on commit a38621b

Please sign in to comment.