diff --git a/frontends/nextjs/src/lib/api/retry.test.ts b/frontends/nextjs/src/lib/api/retry.test.ts index d19626b2d..992995fb8 100644 --- a/frontends/nextjs/src/lib/api/retry.test.ts +++ b/frontends/nextjs/src/lib/api/retry.test.ts @@ -20,9 +20,11 @@ describe('retry utilities', () => { { statusCode: 503, shouldRetry: true, description: 'service unavailable (retryable)' }, { statusCode: 429, shouldRetry: true, description: 'rate limited (retryable)' }, ])('should handle $description correctly', async ({ statusCode, shouldRetry }) => { + let callCount = 0 const mockFetch = vi.fn(async () => { // eslint-disable-line @typescript-eslint/require-await + const currentCall = callCount++ return new Response(JSON.stringify({ test: 'data' }), { - status: shouldRetry ? (mockFetch.mock.calls.length === 0 ? statusCode : 200) : statusCode, + status: shouldRetry ? (currentCall === 0 ? statusCode : 200) : statusCode, }) }) @@ -112,9 +114,10 @@ describe('retry utilities', () => { throw new Error('Network error') }) - const promise = retryFetch(mockFetch, { maxRetries: 2, initialDelayMs: 10 }) - // Fast-forward through all retry delays + const promise = retryFetch(mockFetch, { maxRetries: 2, initialDelayMs: 10 }) + // Attach a catch handler to prevent unhandled rejection warning + promise.catch(() => {}) await vi.advanceTimersByTimeAsync(500) await expect(promise).rejects.toThrow('Network error') @@ -180,8 +183,10 @@ describe('retry utilities', () => { throw new Error('Persistent error') }) + // Fast-forward through all retry delays const promise = retry(mockFn, { maxRetries: 2, initialDelayMs: 10 }) - + // Attach a catch handler to prevent unhandled rejection warning + promise.catch(() => {}) await vi.advanceTimersByTimeAsync(500) await expect(promise).rejects.toThrow('Persistent error') diff --git a/frontends/nextjs/src/lib/compiler/index.ts b/frontends/nextjs/src/lib/compiler/index.ts index c744ba10e..9810bb5fd 100644 --- a/frontends/nextjs/src/lib/compiler/index.ts +++ b/frontends/nextjs/src/lib/compiler/index.ts @@ -37,7 +37,7 @@ export async function compile(source: string, options?: CompileOptions): Promise return { code: result.code, // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing - map: (result.map !== null && result.map !== undefined) ? result.map : undefined, + map: (result.map !== null && result.map !== undefined && result.map !== '') ? result.map : undefined, } } catch (error) { // Return compilation error as a comment in the code diff --git a/frontends/nextjs/src/lib/entities/api-client.ts b/frontends/nextjs/src/lib/entities/api-client.ts index 1e32bf64f..cc5af2eec 100644 --- a/frontends/nextjs/src/lib/entities/api-client.ts +++ b/frontends/nextjs/src/lib/entities/api-client.ts @@ -72,7 +72,12 @@ export async function fetchEntityList( }) if (!response.ok) { - const errorData = await response.json().catch(() => ({ error: 'Unknown error' })) as { error?: string } + let errorData: { error?: string } = { error: 'Unknown error' } + try { + errorData = await response.json() as { error?: string } + } catch { + // If JSON parsing fails, use default error + } return { error: errorData.error ?? `HTTP ${response.status}`, @@ -121,7 +126,12 @@ export async function fetchEntity( }) if (!response.ok) { - const errorData = await response.json().catch(() => ({ error: 'Unknown error' })) as { error?: string } + let errorData: { error?: string } = { error: 'Unknown error' } + try { + errorData = await response.json() as { error?: string } + } catch { + // If JSON parsing fails, use default error + } return { error: errorData.error ?? `HTTP ${response.status}`, @@ -172,7 +182,12 @@ export async function createEntity( }) if (!response.ok) { - const errorData = await response.json().catch(() => ({ error: 'Unknown error' })) as { error?: string } + let errorData: { error?: string } = { error: 'Unknown error' } + try { + errorData = await response.json() as { error?: string } + } catch { + // If JSON parsing fails, use default error + } return { error: errorData.error ?? `HTTP ${response.status}`, @@ -225,7 +240,12 @@ export async function updateEntity( }) if (!response.ok) { - const errorData = await response.json().catch(() => ({ error: 'Unknown error' })) as { error?: string } + let errorData: { error?: string } = { error: 'Unknown error' } + try { + errorData = await response.json() as { error?: string } + } catch { + // If JSON parsing fails, use default error + } return { error: errorData.error ?? `HTTP ${response.status}`, @@ -275,7 +295,12 @@ export async function deleteEntity( }) if (!response.ok) { - const errorData = await response.json().catch(() => ({ error: 'Unknown error' })) as { error?: string } + let errorData: { error?: string } = { error: 'Unknown error' } + try { + errorData = await response.json() as { error?: string } + } catch { + // If JSON parsing fails, use default error + } return { error: errorData.error ?? `HTTP ${response.status}`, diff --git a/frontends/nextjs/src/lib/middleware/auth-middleware.ts b/frontends/nextjs/src/lib/middleware/auth-middleware.ts index 41f0bbcf2..b79efb7fb 100644 --- a/frontends/nextjs/src/lib/middleware/auth-middleware.ts +++ b/frontends/nextjs/src/lib/middleware/auth-middleware.ts @@ -85,7 +85,7 @@ export async function authenticate( const user = await getCurrentUser() // Check if user is authenticated - if (user === null) { + if (user === null || user === undefined) { return { success: false, error: NextResponse.json(