corr add group

This commit is contained in:
alma 2026-01-14 12:37:55 +01:00
parent 2f1c7bacf4
commit faf6397f30
2 changed files with 37 additions and 9 deletions

View File

@ -207,11 +207,25 @@ export async function POST(req: Request) {
// 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
// Read response as text first (can only read body once)
const text = await response.text();
if (text.trim()) {
// Try to parse as JSON
try {
const errorData = JSON.parse(text);
// Keycloak error format: { errorMessage: "..." } or { error: "..." }
errorMessage = errorData.errorMessage || errorData.error || errorData.message || errorMessage;
} catch {
// If not JSON, use the text as error message
errorMessage = text;
}
} else {
// Empty response, use status text
errorMessage = response.statusText || errorMessage;
}
} catch (readError) {
// If reading response fails, use status text
errorMessage = response.statusText || errorMessage;
}

View File

@ -495,10 +495,24 @@ export default function EquipePage() {
// 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
// Read response as text first (can only read body once)
const text = await response.text();
if (text.trim()) {
// Try to parse as JSON
try {
const errorData = JSON.parse(text);
errorMessage = errorData.message || errorData.error || errorMessage;
} catch {
// If not JSON, use the text as error message
errorMessage = text;
}
} else {
// Empty response, use status text
errorMessage = response.statusText || errorMessage;
}
} catch (readError) {
// If reading response fails, use status text
errorMessage = response.statusText || errorMessage;
}
throw new Error(errorMessage);