Se agrego console.log para verificar el error que muestra
This commit is contained in:
@@ -1,27 +1,35 @@
|
||||
// src/app/api/directorioPorArea/route.js
|
||||
|
||||
import { NextResponse } from 'next/server';
|
||||
import axios from 'axios';
|
||||
|
||||
export async function POST(request) {
|
||||
const { Nombre = '', Apellidos = '', IdUnidadResponsable } = await request.json();
|
||||
const { IdUnidadResponsable } = await request.json();
|
||||
|
||||
if (!IdUnidadResponsable) {
|
||||
return NextResponse.json({ error: 'IdUnidadResponsable es requerido' }, { status: 400 });
|
||||
}
|
||||
|
||||
const apiUrl = process.env.API_URL_CON_PARAMS; // Ejemplo: https://.../consultaDirectorioPorArea?ve=...&uf=...
|
||||
|
||||
const apiUrl = process.env.API_URL_CON_PARAMS;
|
||||
|
||||
try {
|
||||
const response = await axios.post(apiUrl, {
|
||||
Nombre,
|
||||
Apellidos,
|
||||
IdUnidadResponsable: Number(IdUnidadResponsable),
|
||||
}, {
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
const response = await axios.post(
|
||||
apiUrl,
|
||||
{ IdUnidadResponsable: Number(IdUnidadResponsable) },
|
||||
{ headers: { 'Content-Type': 'application/json' } } // Esto sí es válido
|
||||
);
|
||||
|
||||
return NextResponse.json(response.data);
|
||||
} catch (error) {
|
||||
console.error('Error en API proxy:', error.response?.data || error.message || error);
|
||||
console.error('Error en API:', error.message);
|
||||
if (error.response) {
|
||||
console.error('Status:', error.response.status);
|
||||
console.error('Data:', error.response.data);
|
||||
} else if (error.request) {
|
||||
console.error('No hubo respuesta del servidor externo');
|
||||
} else {
|
||||
console.error('Error al configurar la petición:', error.message);
|
||||
}
|
||||
return NextResponse.json({ error: 'Error al consultar la API externa' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,11 +16,8 @@ export default function Home() {
|
||||
|
||||
try {
|
||||
const response = await axios.post('/api/directorioPorArea', {
|
||||
Nombre: nombre,
|
||||
Apellidos: '',
|
||||
IdUnidadResponsable: parseInt(area),
|
||||
});
|
||||
|
||||
console.log(response.data);
|
||||
setResultados(response.data || []);
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user