mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 07:53:23 +00:00
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:
@ -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)
|
||||
};
|
||||
Reference in New Issue
Block a user