WIP: Implement frontend

This commit is contained in:
Simon Grimme
2022-07-21 00:29:00 +02:00
parent 6b89690180
commit cc1e02a1ca
109 changed files with 22662 additions and 670 deletions
@@ -0,0 +1,18 @@
import { Injectable } from '@angular/core';
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Config } from '../config/Config';
@Injectable()
export class ApiUrlInterceptor implements HttpInterceptor {
constructor() {
}
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
request = request.clone({
url: Config.apiBasePath + request.url
});
return next.handle(request);
}
}
@@ -0,0 +1,39 @@
import { Injectable } from '@angular/core';
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Observable, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { ApiErrorResponse } from '../models/dtos/ApiErrorResponse';
import { DialogService } from '../services/dialog.service';
@Injectable()
export class ErrorInterceptor implements HttpInterceptor {
constructor(private dialogService: DialogService) {
}
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(request).pipe(catchError((err: ApiErrorResponse) => {
switch (err.status) {
case 400:
if (err.error.message === 'Validation error') {
this.dialogService.showErrorDialog(JSON.stringify(err.error.errors));
} else {
this.dialogService.showErrorDialog(err.error.message);
}
break;
case 401:
this.dialogService.showErrorDialog(err.error.message);
break;
case 409:
case 500:
this.dialogService.showErrorDialog(err.error.message);
break;
case 503:
case 504:
this.dialogService.showErrorDialog('Can\'t reach the backend at the moment.\n' +
'Please ensure that the backend is running and try again');
break;
}
return throwError(err);
}));
}
}