Files
smartguide/webapp/src/app/app.config.ts
T

86 lines
2.8 KiB
TypeScript

import { ApplicationConfig, inject, LOCALE_ID } from '@angular/core';
import {
NavigationError,
provideRouter,
Router,
withComponentInputBinding,
withNavigationErrorHandler,
withRouterConfig,
} from '@angular/router';
import { routes } from './app.routes';
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
import {
HttpErrorResponse,
provideHttpClient,
withInterceptors,
} from '@angular/common/http';
import locale from '@angular/common/locales/de';
import { registerLocaleData } from '@angular/common';
import { authenticationInterceptor } from './shared/interceptors/authentication.interceptor';
import { MAT_FORM_FIELD_DEFAULT_OPTIONS } from '@angular/material/form-field';
import { MatPaginatorIntl } from '@angular/material/paginator';
import { PaginatorIntl } from './resolvers/utils/paginatorIntl';
import { provideEchartsCore } from 'ngx-echarts';
import { ErrorService } from './shared/services/error.service';
import { provideApi } from './api/provide-api';
registerLocaleData(locale);
export const appConfig: ApplicationConfig = {
providers: [
{ provide: LOCALE_ID, useValue: 'de' },
{
provide: MAT_FORM_FIELD_DEFAULT_OPTIONS,
useValue: { appearance: 'outline' },
},
{ provide: MatPaginatorIntl, useClass: PaginatorIntl },
provideRouter(
routes,
withComponentInputBinding(),
withRouterConfig({ onSameUrlNavigation: 'reload' }),
withNavigationErrorHandler((navigationError: NavigationError) => {
const router = inject(Router);
const errorService = inject(ErrorService);
if (
router.url.includes('/error') ||
router.currentNavigation()?.extractedUrl.toString().includes('/error')
) {
console.error(
'Kritischer Fehler beim Laden der Fehlerseite selbst:',
navigationError,
);
return;
}
console.error('Fehler beim Navigieren:', navigationError);
const error = navigationError.error;
let errorMessage: string = 'Unbekannter Fehler';
if (error instanceof HttpErrorResponse) {
errorMessage = error.error?.message || 'Unbekannter HTTP-Fehler';
}
errorService.setError({
statusCode: error.status || 500,
title: 'Daten-Fehler',
message: 'Die Daten für diese Ansicht konnten nicht geladen werden.',
errorDetails: errorMessage,
});
setTimeout(() => {
router.navigate(['/error'], { replaceUrl: true });
});
}),
),
provideHttpClient(withInterceptors([authenticationInterceptor])),
provideApi({
basePath: '/inse-webapp',
withCredentials: true,
}),
provideAnimationsAsync(),
provideEchartsCore({ echarts: () => import('echarts') }),
],
};