From be25b9e068c329806db01757dbe4a4fb7fc822e4 Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Tue, 10 Dec 2019 14:50:20 +0100 Subject: [PATCH] minor bugfixes --- src/backend/middlewares/RenderingMWs.ts | 11 ++--- src/backend/model/tasks/tasks/IndexingTask.ts | 2 +- src/common/entities/Error.ts | 5 +- .../app/model/notification.service.ts | 49 ++++++++++--------- 4 files changed, 35 insertions(+), 32 deletions(-) diff --git a/src/backend/middlewares/RenderingMWs.ts b/src/backend/middlewares/RenderingMWs.ts index 1a8f18d..a4e804d 100644 --- a/src/backend/middlewares/RenderingMWs.ts +++ b/src/backend/middlewares/RenderingMWs.ts @@ -66,14 +66,11 @@ export class RenderingMWs { if (err.details) { Logger.warn('Handled error:'); console.log(err); + delete (err.details); // do not send back error object to the client side + + // hide error details for non developers if (!(req.session.user && req.session.user.role >= UserRoles.Developer)) { - delete (err.details); - } else { - try { - err.details = err.details.toString() || err.details; - } catch (err) { - console.error(err); - } + delete (err.detailsStr); } } const message = new Message(err, null); diff --git a/src/backend/model/tasks/tasks/IndexingTask.ts b/src/backend/model/tasks/tasks/IndexingTask.ts index d96d4e2..c31cada 100644 --- a/src/backend/model/tasks/tasks/IndexingTask.ts +++ b/src/backend/model/tasks/tasks/IndexingTask.ts @@ -9,7 +9,7 @@ import {MediaDTO} from '../../../../common/entities/MediaDTO'; import {ProjectPath} from '../../../ProjectPath'; import {ThumbnailGeneratorMWs} from '../../../middlewares/thumbnail/ThumbnailGeneratorMWs'; import {Task} from './Task'; -import {ConfigTemplateEntry, DefaultsTasks, TaskDTO} from '../../../../common/entities/task/TaskDTO'; +import {ConfigTemplateEntry, DefaultsTasks} from '../../../../common/entities/task/TaskDTO'; import {ServerConfig} from '../../../../common/config/private/IPrivateConfig'; declare const global: any; diff --git a/src/common/entities/Error.ts b/src/common/entities/Error.ts index 07dadf3..bdc64b9 100644 --- a/src/common/entities/Error.ts +++ b/src/common/entities/Error.ts @@ -23,10 +23,13 @@ export enum ErrorCodes { } export class ErrorDTO { + public detailsStr: string; + constructor(public code: ErrorCodes, public message?: string, public details?: any) { + this.detailsStr = (this.details ? this.details.toString() : ''); } toString(): string { - return '[' + ErrorCodes[this.code] + '] ' + this.message + (this.details ? this.details.toString() : ''); + return '[' + ErrorCodes[this.code] + '] ' + this.message + this.detailsStr; } } diff --git a/src/frontend/app/model/notification.service.ts b/src/frontend/app/model/notification.service.ts index 48699cd..f50288c 100644 --- a/src/frontend/app/model/notification.service.ts +++ b/src/frontend/app/model/notification.service.ts @@ -32,25 +32,33 @@ export class NotificationService { }); } + get Toastr(): ToastrService { + return this._toastr; + } + async getServerNotifications() { - this.notifications = await this._networkService.getJson('/notifications'); - this.notifications.forEach((noti) => { - let msg = noti.message; - if (noti.details) { - msg += ' Details: ' + JSON.stringify(noti.details); - } - switch (noti.type) { - case NotificationType.error: - this.error(msg, this.i18n('Server error')); - break; - case NotificationType.warning: - this.warning(msg, this.i18n('Server error')); - break; - case NotificationType.info: - this.info(msg, this.i18n('Server info')); - break; - } - }); + try { + this.notifications = (await this._networkService.getJson('/notifications')) || []; + this.notifications.forEach((noti) => { + let msg = noti.message; + if (noti.details) { + msg += ' Details: ' + JSON.stringify(noti.details); + } + switch (noti.type) { + case NotificationType.error: + this.error(msg, this.i18n('Server error')); + break; + case NotificationType.warning: + this.warning(msg, this.i18n('Server error')); + break; + case NotificationType.info: + this.info(msg, this.i18n('Server info')); + break; + } + }); + } catch (e) { + console.error(e); + } } success(text: string, title: string = null): void { @@ -68,9 +76,4 @@ export class NotificationService { info(text: string, title: string = null): void { this._toastr.info(text, title, this.options); } - - - get Toastr(): ToastrService { - return this._toastr; - } }