fix(gateway): graceful degradation when MySQL is unavailable

Instead of throwing and crashing the gateway when MySQL connection
fails, close the broken pool and continue with pool=null so the
isAvailable() guard handles it gracefully.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
yushen 2026-02-10 16:04:47 +08:00
parent dc60cb754d
commit 483f4a2f59

View file

@ -40,7 +40,11 @@ export class DatabaseService implements OnModuleInit, OnModuleDestroy {
const message = error instanceof Error ? error.message : String(error);
console.log("[DatabaseService] Error:", message);
this.logger.error(`Failed to connect to MySQL: ${message}`);
throw error;
// Graceful degradation: close broken pool, keep this.pool = null
if (this.pool) {
await this.pool.end().catch(() => {});
this.pool = null;
}
}
}