async function createStudent(token, data) {
try {
const response = await fetch('https://api.chessplay.io/api/v1/students/', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});
if (!response.ok) {
const error = await response.json();
if (response.status === 400) {
console.error('Validation error:', error);
} else if (response.status === 401) {
console.error('Authentication failed. Login again.');
} else if (response.status === 403) {
console.error('Need admin permissions.');
}
throw new Error(error.detail || 'Request failed');
}
return await response.json();
} catch (error) {
console.error('Error:', error);
throw error;
}
}