Fix JSON parsing error in Google Calendar initialization

- Add try-catch for JSON.parse with better error handling
- Validate credentials structure before use
- Add detailed error logging for debugging
- Prevent build failure from invalid GOOGLE_SERVICE_ACCOUNT_JSON

Fixes SyntaxError during Next.js build process
This commit is contained in:
Marco Gallegos
2026-01-18 09:54:51 -06:00
parent 439cc80546
commit 02b933d893

View File

@@ -46,7 +46,19 @@ class GoogleCalendarService {
return;
}
const credentials = JSON.parse(serviceAccountJson) as ServiceAccountConfig;
let credentials: ServiceAccountConfig;
try {
credentials = JSON.parse(serviceAccountJson) as ServiceAccountConfig;
} catch (jsonError) {
console.error('GoogleCalendar: Failed to parse GOOGLE_SERVICE_ACCOUNT_JSON', jsonError);
console.error('GoogleCalendar: Service account JSON value:', serviceAccountJson);
throw new Error('Invalid GOOGLE_SERVICE_ACCOUNT_JSON format. Please check environment variable.');
}
if (!credentials.type || !credentials.project_id || !credentials.private_key) {
throw new Error('Invalid GOOGLE_SERVICE_ACCOUNT_JSON: Missing required fields');
}
const auth = new google.auth.GoogleAuth({
credentials,