refactor: Transformation des requetes vers le back en action ajout des

erreurs 400 et refresh lors d'un envoie de formulaire
This commit is contained in:
Luc SORIGNET
2025-01-13 14:21:44 +01:00
parent c4d45426b5
commit 147a70135d
23 changed files with 2421 additions and 314 deletions

View File

@ -5,22 +5,35 @@ import {
BE_SCHOOL_PLANNINGS_URL
} from '@/utils/Url';
const requestResponseHandler = async (response) => {
const body = await response.json();
if (response.ok) {
return body;
}
// Throw an error with the JSON body containing the form errors
const error = new Error('Form submission error');
error.details = body;
throw error;
}
export const fetchSpecialities = () => {
return fetch(`${BE_SCHOOL_SPECIALITIES_URL}`)
.then(response => response.json())
.then(requestResponseHandler)
};
export const fetchTeachers = () => {
return fetch(`${BE_SCHOOL_TEACHERS_URL}`)
.then(response => response.json())
.then(requestResponseHandler)
};
export const fetchClasses = () => {
return fetch(`${BE_SCHOOL_SCHOOLCLASSES_URL}`)
.then(response => response.json())
.then(requestResponseHandler)
};
export const fetchSchedules = () => {
return fetch(`${BE_SCHOOL_PLANNINGS_URL}`)
.then(response => response.json())
.then(requestResponseHandler)
};