corr add group
This commit is contained in:
parent
ea11cfd23b
commit
2f1c7bacf4
@ -184,6 +184,12 @@ export async function POST(req: Request) {
|
||||
}
|
||||
|
||||
const token = await getAdminToken();
|
||||
if (!token) {
|
||||
return NextResponse.json(
|
||||
{ message: "Erreur d'authentification avec Keycloak" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
const response = await fetch(
|
||||
`${process.env.KEYCLOAK_BASE_URL}/admin/realms/${process.env.KEYCLOAK_REALM}/groups`,
|
||||
@ -198,7 +204,21 @@ export async function POST(req: Request) {
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Échec de la création du groupe');
|
||||
// Try to get error details from Keycloak
|
||||
let errorMessage = 'Échec de la création du groupe';
|
||||
try {
|
||||
const errorData = await response.json();
|
||||
// Keycloak error format: { errorMessage: "..." } or { error: "..." }
|
||||
errorMessage = errorData.errorMessage || errorData.error || errorData.message || errorMessage;
|
||||
} catch {
|
||||
// If response is not JSON, use status text
|
||||
errorMessage = response.statusText || errorMessage;
|
||||
}
|
||||
|
||||
return NextResponse.json(
|
||||
{ message: errorMessage },
|
||||
{ status: response.status }
|
||||
);
|
||||
}
|
||||
|
||||
const groupData = await response.json();
|
||||
|
||||
@ -492,21 +492,29 @@ export default function EquipePage() {
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({}));
|
||||
throw new Error(errorData.message || "Failed to create group");
|
||||
// Try to parse error message from response
|
||||
let errorMessage = "Échec de la création du groupe";
|
||||
try {
|
||||
const errorData = await response.json();
|
||||
errorMessage = errorData.message || errorData.error || errorMessage;
|
||||
} catch {
|
||||
// If response is not JSON, use status text
|
||||
errorMessage = response.statusText || errorMessage;
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
const newGroup = await response.json();
|
||||
setGroups(prev => [...prev, newGroup]);
|
||||
setNewGroupDialogOpen(false);
|
||||
setNewGroupName("");
|
||||
toast({ title: "Succès", description: "Groupe créé" });
|
||||
toast({ title: "Succès", description: "Groupe créé avec succès" });
|
||||
fetchData(); // Refresh data
|
||||
} catch (error) {
|
||||
console.error("Error creating group:", error);
|
||||
toast({
|
||||
title: "Erreur",
|
||||
description: error instanceof Error ? error.message : "Échec de la création",
|
||||
description: error instanceof Error ? error.message : "Échec de la création du groupe",
|
||||
variant: "destructive"
|
||||
});
|
||||
} finally {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user