Basic structure for global error handling

This commit is contained in:
Finn Mißfeldt 2019-11-18 19:32:46 +01:00
parent 8b3c6b34c9
commit 9405cdfed6
4 changed files with 43 additions and 0 deletions

View File

@ -35,6 +35,8 @@ import { NoAccessComponent } from 'app/components/no-access/no-access.component'
import { RemoveConfirmationService } from './services/remove-confirmation/remove-confirmation.service';
import { FormsValidatorService } from './shared/services/forms/forms-validator.service';
import { UploadService } from './shared/services/upload/upload.service';
import { ErrorsService } from './shared/services/errors/errors.service';
/**
* Components
@ -107,6 +109,7 @@ export function startupServiceFactory(startupService: StartupService): () => Pro
RemoveConfirmationService,
FormsValidatorService,
UploadService,
ErrorsService,
],
bootstrap: [AppComponent]
})

View File

@ -0,0 +1,14 @@
import { ErrorHandler } from '@angular/core';
import { ERROR_TYPES, errors } from '../services/general-modal/errors';
export class ErrorModel {
head: string;
body: string;
errObj?: ErrorHandler;
constructor(key: ERROR_TYPES, passedError?: ErrorHandler) {
this.head = errors.get(key).name;
this.body = errors.get(key).text;
this.errObj = passedError;
}
}

View File

@ -0,0 +1,24 @@
import { ErrorModel } from '../../models/error-model';
import {Pair} from '../../models/pair';
export enum ERROR_TYPES {
NO_AUTH,
EXP_AUTH,
NO_ACCESS,
}
// TODO: funktioniert unser Pair hierfür? -> Konstruktor checken!
export const errors = new Map<ERROR_TYPES, Pair> ([
[ERROR_TYPES.NO_AUTH, new Pair(
'Authentication required',
'You need to be logged in to perform this action.'
)],
[ERROR_TYPES.EXP_AUTH, new Pair(
'Authentication expired',
'Your session has expired, log in to perform this action.'
)],
[ERROR_TYPES.NO_ACCESS, new Pair(
'Access denied',
'You have no permission to perform this action.'
)],
]);

View File

@ -2,6 +2,8 @@ import { Injectable } from '@angular/core';
import { Subject, Observable } from 'rxjs';
import { MessageModal } from 'app/models/message-modal';
import { errors as ERRORS } from './errors';
@Injectable()
export class GeneralModalService {
private messageTriggered = new Subject<MessageModal>();