fix whole app crash when no rejection text
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 20s

This commit is contained in:
2026-08-03 21:59:04 +05:00
parent d2fd218ee4
commit d536448d2b
+17 -9
View File
@@ -51,6 +51,14 @@ export async function rejectUser(
const userId = formData.get("userId") as string;
const rejection_details = formData.get("rejection_details") as string;
if (!rejection_details?.trim()) {
return {
message: "Rejection details are required.",
fieldErrors: { rejection_details: ["Rejection details are required."] },
payload: formData,
};
}
const response = await apiClient.delete(
`/api/auth/users/${userId}/reject/`,
{ data: { rejection_details } },
@@ -65,17 +73,17 @@ export async function rejectUser(
};
}
if (response.status < 200 || response.status >= 300) {
const errorData = (response.data ?? {}) as ApiError;
throw new Error(
errorData.message || errorData.detail || "Failed to reject user",
);
}
const error = (response.data ?? {}) as ApiError;
const message =
error.message || error.detail || "Failed to reject user.";
// The backend requires a non-empty reason; surface that as a field error so
// the textarea highlights, otherwise just toast the message.
const isReasonError = /rejection details/i.test(message);
return {
message: error.message || error.detail || "An unexpected error occurred.",
fieldErrors: {},
message,
fieldErrors: isReasonError
? { rejection_details: [message] }
: {},
payload: formData,
};
}