Refactor error logging across the application to use a centralized logger

- Introduced a new logger utility (`logError`) to standardize error logging.
- Replaced all instances of `console.error` with `logError` in various API routes and libraries.
- Enhanced error logging to sanitize sensitive information, particularly for Prisma and Stripe errors.
- Ensured consistent error handling and logging practices throughout the codebase.
This commit is contained in:
Yusuf İpek
2026-04-10 21:10:09 +03:00
parent 07f7b6fb02
commit 8014fc3986
60 changed files with 235 additions and 115 deletions
+5 -4
View File
@@ -5,6 +5,7 @@ import { rateLimit } from '@/lib/rate-limit';
import nodemailer from 'nodemailer';
import { testEmailHtml } from '@/lib/notifications';
import { apiErrors, successResponse, withCacheControl } from '@/lib/api-response';
import { logError } from '@/lib/logger';
// GET /api/settings/notifications — Fetch current notification preferences
export async function GET() {
@@ -35,7 +36,7 @@ export async function GET() {
return withCacheControl(response, 'private, max-age=30, stale-while-revalidate=60');
} catch (error) {
console.error('Error fetching notification settings:', error);
logError('Error fetching notification settings:', error);
return apiErrors.internalError('Failed to fetch settings');
}
}
@@ -102,7 +103,7 @@ export async function PUT(request: NextRequest) {
const response = successResponse(settings);
return withCacheControl(response, 'private, no-store');
} catch (error) {
console.error('Error updating notification settings:', error);
logError('Error updating notification settings:', error);
return apiErrors.internalError('Failed to update settings');
}
}
@@ -197,7 +198,7 @@ export async function POST(request: NextRequest) {
html: testEmailHtml(),
});
} catch (emailErr) {
console.error('SMTP test email failed:', emailErr);
logError('SMTP test email failed:', emailErr);
return apiErrors.internalError('Failed to send test email — check SMTP settings');
}
@@ -207,7 +208,7 @@ export async function POST(request: NextRequest) {
return apiErrors.badRequest('Unknown channel');
} catch (error) {
console.error('Error testing notification:', error);
logError('Error testing notification:', error);
return apiErrors.internalError('Failed to test notification');
}
}