throw 403 error instead of 422 and display toast message

This commit is contained in:
2022-02-25 13:11:30 +01:00
parent 68bfca8a1f
commit 16cca07e12
7 changed files with 17 additions and 44 deletions

View File

@@ -11,16 +11,19 @@ const makeFetch = (method, url, body) => {
})
.then(response => {
if (response.ok) {
console.log('200 error')
return response.json();
}
if (response.status === 422) {
console.log('422 error')
return response.json().then(response => {
throw ValidationException(response)
});
}
if (response.status === 403) {
console.log('403 error')
throw AccessException(response);
}
@@ -92,15 +95,8 @@ const ValidationException = (response) => {
const AccessException = (response) => {
const error = {};
error.name = 'AccessException';
error.violations = ['You are not allowed to perform this action'];
switch (response.url) {
case 'http://localhost:8001/api/1.0/person/accompanying-course/5183/intensity.json':
error.violations = ['Only the referrer is allowed to change the intensity of a parcours'];
break;
default:
error.violations = ['You are not allowed to perform this action'];
break;
}
return error;
}