Private
Public Access
estado intermedio
This commit is contained in:
1 parent
fcc3952841
commit
617583def5
9 files changed
+52
-165
No files matched your search
@@ -0,0 +1,18 @@
|
||||
import type { Usuario } from '../../types';
|
||||
import { API_URL } from '../env';
|
||||
import { getToken } from './token';
|
||||
|
||||
async function handleResponse<T>(response: Response): Promise<T> {
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ message: 'Error desconocido' }));
|
||||
throw new Error(error.message || 'Error en la petición');
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
|
||||
export async function obtenerUsuarioPorId(id: number): Promise<Usuario> {
|
||||
const response = await fetch(`${API_URL}/usuario/${id}`, {
|
||||
headers: { Authorization: `Bearer ${getToken()}` }
|
||||
});
|
||||
return handleResponse<Usuario>(response);
|
||||
}
|
||||
Reference in new issue
Block a user