feat(services): handle MySQL connection errors with process exit

Updated `mysql.service.ts` to handle MySQL connection errors by terminating the process instead of throwing a generic error. This change provides a more direct response to database connection failures.

Signed-off-by: Mathis <yidhra@tuta.io>
This commit is contained in:
Mathis H (Avnyr) 2024-04-29 09:53:18 +02:00
parent 37ec62405e
commit c024770b4a
Signed by: Mathis
GPG Key ID: DD9E0666A747D126

View File

@ -5,6 +5,7 @@ import type {IDbBrand} from "@interfaces/database/IDbBrand";
import type {IDbStatusResult} from "@interfaces/database/IDbStatusResult"; import type {IDbStatusResult} from "@interfaces/database/IDbStatusResult";
import mysql, {type Connection, type ConnectionOptions} from 'mysql2'; import mysql, {type Connection, type ConnectionOptions} from 'mysql2';
import {Logger} from "tslog"; import {Logger} from "tslog";
import process from "node:process";
const access: ConnectionOptions = { const access: ConnectionOptions = {
@ -28,7 +29,7 @@ class MysqlHandler {
this.Connection.connect((err) => { this.Connection.connect((err) => {
if (err) { if (err) {
this.Logger.error(`Error connecting to MySQL: ${err}`); this.Logger.error(`Error connecting to MySQL: ${err}`);
throw new Error() process.exit(1);
} }
this.Logger.info(`Connected to MySQL database (${access.database})`); this.Logger.info(`Connected to MySQL database (${access.database})`);
}); });