From da2a361d08a63afbcae39e1ab2dfaf5fd60fbba4 Mon Sep 17 00:00:00 2001 From: stratuma Date: Mon, 20 May 2024 19:21:55 +0200 Subject: [PATCH] more logging added --- src/api/api.ts | 20 ++++++++++++++++++++ src/api/routes/service/service.service.ts | 9 +-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/api/api.ts b/src/api/api.ts index 53b5488..776eeb0 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -6,6 +6,7 @@ import { sequelize } from './db/database' import serviceRoutes from './routes/service/service.route' import { app } from 'electron' import winston from 'winston' +import { messageBox } from '../electron/background' const logger = winston.createLogger({ level: 'info', @@ -58,9 +59,24 @@ async function startAPI() { server.listen({ port: 9941 }, (err, address) => { if (err) { console.error(err) + messageBox('error', ['Cancel'], 2, 'Unable to start backend server', 'Unable to connect to the database', JSON.stringify(err)) + logger.log({ + level: 'error', + message: 'Unable to start backend server', + error: err, + timestamp: new Date().toISOString(), + section: 'backendServer' + }) + app.quit(); return } console.log(`Server is listening on ${address}`) + logger.log({ + level: 'info', + message: `Backend started on ${address}`, + timestamp: new Date().toISOString(), + section: 'backendServer' + }) }) } @@ -76,6 +92,7 @@ async function startDB() { }) } catch (error) { console.error('Unable to connect to the database:', error) + messageBox('error', ['Cancel'], 2, 'Unable to connect to the database', 'Unable to connect to the database', JSON.stringify(error)) logger.log({ level: 'error', message: 'Unable to connect to the database', @@ -83,6 +100,7 @@ async function startDB() { timestamp: new Date().toISOString(), section: 'databaseConnection' }) + app.quit(); } try { @@ -96,6 +114,7 @@ async function startDB() { }) } catch (error) { console.log('Failed to synchronize Models') + messageBox('error', ['Cancel'], 2, 'Failed to synchronize database Models', 'Failed to synchronize database Models', JSON.stringify(error)) logger.log({ level: 'error', message: 'Failed to synchronize Models', @@ -103,6 +122,7 @@ async function startDB() { timestamp: new Date().toISOString(), section: 'databaseSync' }) + app.quit(); } } diff --git a/src/api/routes/service/service.service.ts b/src/api/routes/service/service.service.ts index 18e2b24..44def5c 100644 --- a/src/api/routes/service/service.service.ts +++ b/src/api/routes/service/service.service.ts @@ -459,14 +459,7 @@ export async function downloadCrunchyrollPlaylist( if (!playlist) { await updatePlaylistByID(downloadID, 'failed') console.log('Playlist not found') - messageBox( - 'error', - ['Cancel'], - 2, - 'Playlist not found', - 'Playlist not found', - 'Playlist not found' - ) + messageBox('error', ['Cancel'], 2, 'Playlist not found', 'Playlist not found', 'Playlist not found') server.logger.log({ level: 'error', message: `Playlist not found for Download ${downloadID}`,