Fix guest demo UX and enforce guest limits

This commit is contained in:
Codex Agent
2026-01-21 21:35:40 +01:00
parent a01a7ec399
commit 80dd12bb92
28 changed files with 812 additions and 118 deletions

View File

@@ -0,0 +1,23 @@
import { describe, expect, it, vi } from 'vitest';
import { fetchEvent, FetchEventError } from '../eventApi';
describe('fetchEvent', () => {
it('maps guest_limit_exceeded error codes', async () => {
const originalFetch = global.fetch;
global.fetch = vi.fn().mockResolvedValue({
ok: false,
status: 402,
json: async () => ({
error: { code: 'guest_limit_exceeded', message: 'Limit reached' },
}),
} as Response);
await expect(fetchEvent('token')).rejects.toEqual(
expect.objectContaining<Pick<FetchEventError, 'code'>>({
code: 'guest_limit_exceeded',
})
);
global.fetch = originalFetch;
});
});

View File

@@ -132,6 +132,7 @@ export type FetchEventErrorCode =
| 'token_revoked'
| 'token_rate_limited'
| 'access_rate_limited'
| 'guest_limit_exceeded'
| 'gallery_expired'
| 'event_not_public'
| 'network_error'
@@ -187,6 +188,7 @@ const API_ERROR_CODES: FetchEventErrorCode[] = [
'token_revoked',
'token_rate_limited',
'access_rate_limited',
'guest_limit_exceeded',
'gallery_expired',
'event_not_public',
];
@@ -221,6 +223,8 @@ function defaultMessageForCode(code: FetchEventErrorCode): string {
return 'Zu viele Versuche in kurzer Zeit. Bitte warte einen Moment und versuche es erneut.';
case 'access_rate_limited':
return 'Zu viele Aufrufe in kurzer Zeit. Bitte warte einen Moment und versuche es erneut.';
case 'guest_limit_exceeded':
return 'Dieses Event hat sein Gäste-Limit erreicht. Bitte kontaktiere die Veranstalter:innen.';
case 'gallery_expired':
return 'Die Galerie ist nicht mehr verfügbar.';
case 'event_not_public':
@@ -237,7 +241,11 @@ function defaultMessageForCode(code: FetchEventErrorCode): string {
export async function fetchEvent(eventKey: string): Promise<EventData> {
try {
const res = await fetch(`/api/v1/events/${encodeURIComponent(eventKey)}`);
const res = await fetch(`/api/v1/events/${encodeURIComponent(eventKey)}`, {
headers: {
'X-Device-Id': getDeviceId(),
},
});
if (!res.ok) {
let apiMessage: string | null = null;
let rawCode: unknown;