use fetchWrapper for getUserById.js
This commit is contained in:
@@ -1,23 +1,5 @@
|
||||
import fetchWrapper from "../fetchWrapper.js";
|
||||
|
||||
export default async function getUserById(id) {
|
||||
try {
|
||||
const res = await fetch(`${import.meta.env.VITE_API_URL}/api/users/${id}`, {
|
||||
method: 'GET',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
if (res.status === 404) {
|
||||
return { error: 'not_found' };
|
||||
}
|
||||
throw new Error(`Erreur serveur : ${res.status}`);
|
||||
}
|
||||
|
||||
return await res.json();
|
||||
} catch (err) {
|
||||
console.error('Erreur :', err);
|
||||
return { error: 'server_error' };
|
||||
}
|
||||
return fetchWrapper(`/api/users/${id}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user