Se soluciono autenticacion
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
// src/api/pedimentoDocuments.ts
|
||||
import { fetchWithAuth } from '../fetchWithAuth';
|
||||
|
||||
export interface PedimentoDocument {
|
||||
id: string;
|
||||
@@ -19,26 +20,25 @@ export interface PedimentoDocumentsResponse {
|
||||
results: PedimentoDocument[];
|
||||
}
|
||||
|
||||
const API_URL = import.meta.env.VITE_EFC_API_URL;
|
||||
const API_URL = (import.meta as any).env.VITE_EFC_API_URL;
|
||||
|
||||
export async function fetchPedimentoDocuments(
|
||||
token: string,
|
||||
pedimentoId: string,
|
||||
page: number = 1,
|
||||
pageSize: number = 10
|
||||
): Promise<PedimentoDocumentsResponse> {
|
||||
const res = await fetch(
|
||||
`${API_URL}/record/documents/?page=${page}&page_size=${pageSize}&pedimento=${pedimentoId}`,
|
||||
{
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
try {
|
||||
const res = await fetchWithAuth(
|
||||
`${API_URL}/record/documents/?page=${page}&page_size=${pageSize}&pedimento=${pedimentoId}`
|
||||
);
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error('No autorizado o error en la petición');
|
||||
}
|
||||
);
|
||||
if (res.status === 401) {
|
||||
throw new Error('SESSION_EXPIRED');
|
||||
|
||||
return res.json();
|
||||
} catch (error) {
|
||||
console.error('Error in fetchPedimentoDocuments:', error);
|
||||
throw error;
|
||||
}
|
||||
if (!res.ok) throw new Error('No autorizado o error en la petición');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user