feat(api): implement retry logic for Mistral API calls in receipt import and AI services

This commit is contained in:
Nils-Johan Gynther
2026-04-19 11:31:05 +02:00
parent 15c24df1a7
commit 045f160655
3 changed files with 107 additions and 74 deletions
+9 -7
View File
@@ -1,19 +1,21 @@
import { NextResponse } from 'next/server';
import { auth } from '../../../auth';
import { NextRequest, NextResponse } from 'next/server';
import { getAuthHeaders } from '../../../lib/auth-headers';
const API_BASE = process.env.NEXT_PUBLIC_API_URL_INTERNAL || 'http://recipe-api:8080';
export const GET = auth(async function GET(req) {
const token = (req.auth as any)?.accessToken as string | undefined;
if (!token) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
export async function GET(req: NextRequest) {
const authHeaders = await getAuthHeaders();
if (!authHeaders.Authorization) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const url = new URL(req.url);
const query = url.searchParams.toString();
const res = await fetch(`${API_BASE}/api/products${query ? `?${query}` : ''}`, {
headers: { Authorization: `Bearer ${token}` },
headers: authHeaders,
cache: 'no-store',
});
const data = await res.json();
return NextResponse.json(data, { status: res.status });
});
}