Replace console.error calls in scraper admin routes with structured scraperLogger
All checks were successful
CI/CD Pipeline - Apartment API / Lint & Test (pull_request) Successful in 41s
CI/CD Pipeline - Apartment API / Send Webhook Notification (pull_request) Successful in 2s
CI/CD Pipeline - Apartment API / Build & Push Image (pull_request) Has been skipped
CI/CD Pipeline - Apartment API / Deploy to Production (pull_request) Has been skipped
CI/CD Pipeline - Apartment API / Scan Dependencies (pull_request) Successful in 13s

Replace 4 raw console.error calls in the scraper admin routes (trigger,
status, history, config endpoints) with structured scraperLogger calls
using createLogger('scraper-admin'). Error objects are now sanitized to
log error.name and error.message instead of raw error objects, ensuring
credential redaction is applied consistently across all scraper
production code paths.
This commit is contained in:
2026-02-06 22:57:33 -07:00
parent d0538334a5
commit ba09cdf8ec

View File

@ -1156,8 +1156,12 @@ const {
getNextScheduledRun
} = require('../jobs/scraperJob');
const { runScrape } = require('../services/scraperService');
const { createLogger } = require('../services/scraperLogger');
const scraperConfig = require('../config/scraper');
// Logger for scraper admin routes
const scraperRouteLogger = createLogger('scraper-admin');
/**
* POST /api/admin/scraper/run
* Trigger a manual scrape
@ -1190,7 +1194,10 @@ router.post('/scraper/run', async (req, res) => {
// Start scrape asynchronously (do not await - return 202 immediately)
runScrape(db, { trigger: 'manual', jobId, dryRun, htmlContent })
.catch((error) => {
console.error('Async scrape failed:', error.message);
scraperRouteLogger.error('Async scrape failed', {
errorType: error.name,
errorMessage: error.message
});
})
.finally(() => releaseLock());
@ -1205,7 +1212,10 @@ router.post('/scraper/run', async (req, res) => {
});
} catch (error) {
console.error('Error triggering scrape:', error);
scraperRouteLogger.error('Error triggering scrape', {
errorType: error.name,
errorMessage: error.message
});
res.status(500).json({ error: 'Failed to start scrape job' });
}
});
@ -1245,7 +1255,10 @@ router.get('/scraper/status', async (req, res) => {
});
} catch (error) {
console.error('Error fetching scraper status:', error);
scraperRouteLogger.error('Error fetching scraper status', {
errorType: error.name,
errorMessage: error.message
});
res.status(503).json({ error: 'Service temporarily unavailable' });
}
});
@ -1295,7 +1308,10 @@ router.get('/scraper/history', async (req, res) => {
res.json({ data: history });
} catch (error) {
console.error('Error fetching scraper history:', error);
scraperRouteLogger.error('Error fetching scraper history', {
errorType: error.name,
errorMessage: error.message
});
res.status(503).json({ error: 'Service temporarily unavailable' });
}
});