feat(api): implement retry logic for Mistral API calls in receipt import and AI services
This commit is contained in:
@@ -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 });
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user