Files
atomic-design-poc/src/app/shared/infrastructure/scenario.interceptor.ts
Edwin van den Houdt e82309786d style: format frontend, docs and skills with prettier; add .prettierignore
One-time prettier --write so the new format:check CI gate starts green.
.prettierignore excludes generated (api-client.ts, documentation.json),
vendored (public/cibg-huisstijl), and backend (dotnet format owns it).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-03 13:39:31 +02:00

34 lines
1.2 KiB
TypeScript

import { HttpErrorResponse, HttpInterceptorFn, HttpResponse } from '@angular/common/http';
import { of, switchMap, throwError, timer } from 'rxjs';
import { delay } from 'rxjs/operators';
import { currentScenario } from './scenario';
/**
* Demo-only: rewrites the timing/outcome of API data requests based on
* ?scenario= so loading / empty / error states can be shown on demand.
* Non-API requests are untouched.
*/
export const scenarioInterceptor: HttpInterceptorFn = (req, next) => {
if (!req.url.includes('/api/')) return next(req);
switch (currentScenario()) {
case 'slow':
return next(req).pipe(delay(2500));
case 'loading':
return next(req).pipe(delay(600_000)); // effectively never resolves
case 'empty':
// '[]' so the typed client parses it to an empty array (notes → Empty state).
return of(new HttpResponse({ status: 200, body: '[]' })).pipe(delay(400));
case 'error':
return timer(400).pipe(
switchMap(() =>
throwError(
() => new HttpErrorResponse({ status: 500, statusText: 'Demo-fout', url: req.url }),
),
),
);
default:
return next(req);
}
};