mirror of
https://github.com/soconnor0919/hristudio.git
synced 2025-12-12 07:04:44 -05:00
feat(api): Enhance study creation and user management with improved error handling and logging
- Updated the study creation endpoint to return JSON responses for errors and success. - Added user existence verification before creating a study. - Enhanced error logging for better debugging. - Refactored user creation in webhooks to use transactions for atomicity. - Improved response structure for webhook processing. - Updated the seed script to streamline role and permission insertion. - Added new permissions for editing studies and participants.
This commit is contained in:
@@ -47,6 +47,11 @@ export default function Studies() {
|
||||
const createStudy = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
try {
|
||||
console.log("Sending study data:", {
|
||||
title: newStudyTitle,
|
||||
description: newStudyDescription
|
||||
});
|
||||
|
||||
const response = await fetch('/api/studies', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -57,12 +62,20 @@ export default function Studies() {
|
||||
description: newStudyDescription,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
console.error("Server response:", errorData);
|
||||
throw new Error(errorData.error || 'Failed to create study');
|
||||
}
|
||||
|
||||
const newStudy = await response.json();
|
||||
setStudies([...studies, newStudy]);
|
||||
setNewStudyTitle("");
|
||||
setNewStudyDescription("");
|
||||
} catch (error) {
|
||||
console.error('Error creating study:', error);
|
||||
alert(error instanceof Error ? error.message : 'Failed to create study');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user