🔧 fix(telegram-bot): improve database connection logging and error messages

- Add connection test on startup (SELECT 1)
- Log masked database URL on connection attempt
- Better error messages for /users command
This commit is contained in:
Till-JS 2026-01-26 11:14:52 +01:00
parent 79e3c09af2
commit 021c6e789e
2 changed files with 23 additions and 9 deletions

View file

@ -31,10 +31,16 @@ export class UsersService implements OnModuleInit {
async onModuleInit() {
if (this.databaseUrl) {
try {
// Mask password in logs
const maskedUrl = this.databaseUrl.replace(/:([^@]+)@/, ':****@');
this.logger.log(`Connecting to database: ${maskedUrl}`);
this.sql = postgres(this.databaseUrl);
this.logger.log('Database connection initialized');
// Test connection
await this.sql`SELECT 1`;
this.logger.log('Database connection initialized and tested successfully');
} catch (error) {
this.logger.warn('Failed to initialize database connection:', error);
this.logger.error('Failed to initialize database connection:', error);
this.sql = null;
}
} else {
this.logger.warn('DATABASE_URL not configured, user stats will be unavailable');