mirror of
https://github.com/towfiqi/serpbear
synced 2025-06-26 18:15:54 +00:00
feat: Adds better error logging for debugging issues
This commit is contained in:
@@ -35,7 +35,7 @@ const cronRefreshkeywords = async (req: NextApiRequest, res: NextApiResponse<CRO
|
||||
|
||||
return res.status(200).json({ started: true });
|
||||
} catch (error) {
|
||||
console.log('ERROR cronRefreshkeywords: ', error);
|
||||
console.log('[ERROR] CRON Refreshing Keywords: ', error);
|
||||
return res.status(400).json({ started: false, error: 'CRON Error refreshing keywords!' });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -92,7 +92,7 @@ export const deleteDomain = async (req: NextApiRequest, res: NextApiResponse<Dom
|
||||
keywordsRemoved: removedKeywordCount,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log('##### Delete Domain Error: ', error);
|
||||
console.log('[ERROR] Deleting Domain: ', req.query.domain, error);
|
||||
return res.status(400).json({ domainRemoved: 0, keywordsRemoved: 0, error: 'Error Deleting Domain' });
|
||||
}
|
||||
};
|
||||
@@ -104,11 +104,15 @@ export const updateDomain = async (req: NextApiRequest, res: NextApiResponse<Dom
|
||||
const { domain } = req.query || {};
|
||||
const { notification_interval, notification_emails } = req.body;
|
||||
|
||||
const domainToUpdate: Domain|null = await Domain.findOne({ where: { domain } });
|
||||
if (domainToUpdate) {
|
||||
domainToUpdate.set({ notification_interval, notification_emails });
|
||||
await domainToUpdate.save();
|
||||
try {
|
||||
const domainToUpdate: Domain|null = await Domain.findOne({ where: { domain } });
|
||||
if (domainToUpdate) {
|
||||
domainToUpdate.set({ notification_interval, notification_emails });
|
||||
await domainToUpdate.save();
|
||||
}
|
||||
return res.status(200).json({ domain: domainToUpdate });
|
||||
} catch (error) {
|
||||
console.log('[ERROR] Updating Domain: ', req.query.domain, error);
|
||||
return res.status(400).json({ domain: null, error: 'Error Updating Domain' });
|
||||
}
|
||||
|
||||
return res.status(200).json({ domain: domainToUpdate });
|
||||
};
|
||||
|
||||
@@ -48,7 +48,7 @@ const getDomainSearchConsoleInsight = async (req: NextApiRequest, res: NextApiRe
|
||||
const response = getInsightFromSCData(scData);
|
||||
return res.status(200).json({ data: response });
|
||||
} catch (error) {
|
||||
console.log('ERROR getDomainSearchConsoleInsight: ', error);
|
||||
console.log('[ERROR] Getting Domain Insight: ', domainname, error);
|
||||
return res.status(400).json({ data: null, error: 'Error Fetching Stats from Google Search Console.' });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -22,7 +22,6 @@ const getKeyword = async (req: NextApiRequest, res: NextApiResponse<KeywordGetRe
|
||||
if (!req.query.id && typeof req.query.id !== 'string') {
|
||||
return res.status(400).json({ error: 'Keyword ID is Required!' });
|
||||
}
|
||||
console.log('KEYWORD: ', req.query.id);
|
||||
|
||||
try {
|
||||
const query = { ID: parseInt((req.query.id as string), 10) };
|
||||
@@ -31,7 +30,7 @@ const getKeyword = async (req: NextApiRequest, res: NextApiResponse<KeywordGetRe
|
||||
const keywords = pareseKeyword && pareseKeyword[0] ? pareseKeyword[0] : null;
|
||||
return res.status(200).json({ keyword: keywords });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.log('[ERROR] Getting Keyword: ', error);
|
||||
return res.status(400).json({ error: 'Error Loading Keyword' });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -65,10 +65,9 @@ const getKeywords = async (req: NextApiRequest, res: NextApiResponse<KeywordsGet
|
||||
const finalKeyword = domainSCData ? integrateKeywordSCData(keyword, domainSCData) : keywordWithSlimHistory;
|
||||
return finalKeyword;
|
||||
});
|
||||
console.log('getKeywords: ', keywords.length);
|
||||
return res.status(200).json({ keywords: processedKeywords });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.log('[ERROR] Getting Domain Keywords for ', domain, error);
|
||||
return res.status(400).json({ error: 'Error Loading Keywords for this Domain.' });
|
||||
}
|
||||
};
|
||||
@@ -107,6 +106,7 @@ const addKeywords = async (req: NextApiRequest, res: NextApiResponse<KeywordsGet
|
||||
refreshAndUpdateKeywords(newKeywords, settings); // Queue the SERP Scraping Process
|
||||
return res.status(201).json({ keywords: keywordsParsed });
|
||||
} catch (error) {
|
||||
console.log('[ERROR] Adding New Keywords ', error);
|
||||
return res.status(400).json({ error: 'Could Not Add New Keyword!' });
|
||||
}
|
||||
} else {
|
||||
@@ -126,6 +126,7 @@ const deleteKeywords = async (req: NextApiRequest, res: NextApiResponse<Keywords
|
||||
const removedKeywordCount: number = await Keyword.destroy(removeQuery);
|
||||
return res.status(200).json({ keywordsRemoved: removedKeywordCount });
|
||||
} catch (error) {
|
||||
console.log('[ERROR] Removing Keyword. ', error);
|
||||
return res.status(400).json({ error: 'Could Not Remove Keyword!' });
|
||||
}
|
||||
};
|
||||
@@ -162,7 +163,7 @@ const updateKeywords = async (req: NextApiRequest, res: NextApiResponse<Keywords
|
||||
}
|
||||
return res.status(400).json({ error: 'Invalid Payload!' });
|
||||
} catch (error) {
|
||||
console.log('ERROR updateKeywords: ', error);
|
||||
console.log('[ERROR] Updating Keyword. ', error);
|
||||
return res.status(200).json({ error: 'Error Updating keywords!' });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -81,5 +81,5 @@ const sendNotificationEmail = async (domain: Domain, settings: SettingsType) =>
|
||||
to: domain.notification_emails || notification_email,
|
||||
subject: `[${domainName}] Keyword Positions Update`,
|
||||
html: emailHTML,
|
||||
});
|
||||
}).catch((err:any) => console.log('[ERROR] Sending Notification Email for', domainName, err?.response || err));
|
||||
};
|
||||
|
||||
@@ -45,7 +45,7 @@ const getDomainSearchConsoleData = async (req: NextApiRequest, res: NextApiRespo
|
||||
const scData = await fetchDomainSCData(domainname);
|
||||
return res.status(200).json({ data: scData });
|
||||
} catch (error) {
|
||||
console.log('ERROR getDomainSearchConsoleData: ', error);
|
||||
console.log('[ERROR] Getting Search Console Data for: ', domainname, error);
|
||||
return res.status(400).json({ data: null, error: 'Error Fetching Data from Google Search Console.' });
|
||||
}
|
||||
};
|
||||
@@ -59,7 +59,7 @@ const cronRefreshSearchConsoleData = async (req: NextApiRequest, res: NextApiRes
|
||||
}
|
||||
return res.status(200).json({ status: 'completed' });
|
||||
} catch (error) {
|
||||
console.log('ERROR cronRefreshkeywords: ', error);
|
||||
console.log('[ERROR] CRON Updating Search Console Data. ', error);
|
||||
return res.status(400).json({ status: 'failed', error: 'Error Fetching Data from Google Search Console.' });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -45,7 +45,7 @@ const updateSettings = async (req: NextApiRequest, res: NextApiResponse<Settings
|
||||
await writeFile(`${process.cwd()}/data/settings.json`, JSON.stringify(securedSettings), { encoding: 'utf-8' });
|
||||
return res.status(200).json({ settings });
|
||||
} catch (error) {
|
||||
console.log('ERROR updateSettings: ', error);
|
||||
console.log('[ERROR] Updating App Settings. ', error);
|
||||
return res.status(200).json({ error: 'Error Updating Settings!' });
|
||||
}
|
||||
};
|
||||
@@ -72,7 +72,7 @@ export const getAppSettings = async () : Promise<SettingsType> => {
|
||||
|
||||
return decryptedSettings;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.log('[ERROR] Getting App Settings. ', error);
|
||||
const settings = {
|
||||
scraper_type: 'none',
|
||||
notification_interval: 'never',
|
||||
|
||||
Reference in New Issue
Block a user