Added service for unrecoverable cases
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Jim Martens 2023-08-23 11:12:41 +02:00
parent 48674b1619
commit 58c9b37a4e
3 changed files with 30 additions and 7 deletions

View File

@ -7,14 +7,16 @@ import {MessageType} from "./model/message-type";
providedIn: 'root'
})
export class MessagesService {
private static UNAUTHENTICATED = $localize `You are not logged in which prevents data from loading`;
private static UNAUTHORIZED = $localize `You don't have sufficient authorization to view the data`;
private static INTERNAL_SERVER_ERROR = $localize `An internal server error occurred. Sorry for the inconvenience.`;
private static UNKNOWN_ERROR = $localize `An unknown error occurred. Sorry for the inconvenience.`;
private static UNAUTHENTICATED = $localize`You are not logged in which prevents data from loading`;
private static UNAUTHORIZED = $localize`You don't have sufficient authorization to view the data`;
private static INTERNAL_SERVER_ERROR = $localize`An internal server error occurred. Sorry for the inconvenience.`;
private static UNKNOWN_ERROR = $localize`An unknown error occurred. Sorry for the inconvenience.`;
private static SERVICE_WORKER_ERROR = $localize`An error with the service worker occurred. Please reload the page.`
constructor(private store: Store) { }
constructor(private store: Store) {
}
logMessage(component: string, type: MessageType) {
logMessage(component: string, type: MessageType, details?: string) {
let text = component + ": ";
switch (type) {
case MessageType.UNAUTHENTICATED:
@ -26,6 +28,12 @@ export class MessagesService {
case MessageType.INTERNAL_SERVER_ERROR:
text += MessagesService.INTERNAL_SERVER_ERROR;
break;
case MessageType.SERVICE_WORKER_ERROR:
text += MessagesService.SERVICE_WORKER_ERROR;
if (details != undefined) {
text += "Details: " + details;
}
break;
default:
text += MessagesService.UNKNOWN_ERROR;
}

View File

@ -1,5 +1,6 @@
export enum MessageType {
UNAUTHENTICATED,
UNAUTHORIZED,
INTERNAL_SERVER_ERROR
INTERNAL_SERVER_ERROR,
SERVICE_WORKER_ERROR
}

View File

@ -0,0 +1,14 @@
import {Injectable} from '@angular/core';
import {SwUpdate} from "@angular/service-worker";
import {MessagesService} from "./messages.service";
import {MessageType} from "./model/message-type";
@Injectable()
export class ServiceWorkerService {
constructor(updates: SwUpdate, messages: MessagesService) {
updates.unrecoverable.subscribe(event => {
messages.logMessage("service-worker", MessageType.SERVICE_WORKER_ERROR, event.reason);
});
}
}