Skip to content

feat(LMS-247): show more information about errors #462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/v2/js/apps/YDSApplicationForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ import {
Tooltip
} from 'components';
import { optionStrType } from 'types/props';
import {
showErrorNotification,
showNotification
} from 'utils';
import { showErrorNotification, showNotification } from 'utils';

// TODO: потестить isPending. Есть какой-то devtools для react-async

Expand Down Expand Up @@ -54,24 +51,28 @@ const submitForm = async (
});
if (!response.ok) {
if (response.status === 400) {
const data = response.json();
const data = await response.json();
console.log(data);
let msg = '<h5>Анкета не была сохранена</h5>';
if (
Object.keys(data).length === 1 &&
Object.prototype.hasOwnProperty.call(data, 'non_field_errors')
) {
msg += data['non_field_errors'];
showErrorNotification(msg);
console.log(`Non field errors: ${data}`);
} else {
msg += 'Одно или более полей пропущены или заполнены некорректно.';
showNotification(msg, { type: 'error', timeout: 3000 });
msg += 'Одно или более полей пропущены или заполнены некорректно:';
msg += `<br/>${JSON.stringify(data)}`;
showNotification(msg, { type: 'error' });
}
} else if (response.status === 403) {
let msg = '<h5>Анкета не была сохранена</h5>Приемная кампания окончена.';
showErrorNotification(msg);
} else {
showErrorNotification(
'Что-то пошло не так. Пожалуйста, обратитесь на почту, указанную вниз анкеты.'
`Что-то пошло не так: код ошибки ${response.status}.<br/>
Пожалуйста, обратитесь на почту, указанную внизу анкеты.`
);
}
} else {
Expand Down Expand Up @@ -152,7 +153,7 @@ function YDSApplicationForm({
setCities(data.map(({ id, name }) => ({ value: id, label: name })));
})
.catch(errors => {
showErrorNotification(`Что-то пошло не так, пожалуйста, обратитесь на почту,
showErrorNotification(`Не удалось загрузить список городов, пожалуйста, обратитесь на почту,
указанную внизу анкеты.<br>${errors.toString()}`);
console.error(errors);
});
Expand Down Expand Up @@ -207,7 +208,7 @@ function YDSApplicationForm({
);
})
.catch(errors => {
showErrorNotification(`Что-то пошло не так, пожалуйста, обратитесь на почту,
showErrorNotification(`Не удалось загрузить список университетов, пожалуйста, обратитесь на почту,
указанную внизу анкеты.<br>${errors.toString()}`);
console.error(errors);
});
Expand All @@ -232,9 +233,8 @@ function YDSApplicationForm({
rules.course = value === 'yes' ? { required: msgRequired } : {};
register('course', rules.course);
}
if (name === 'campaign' && value === mskStrCampaignId) {
const required = value === 'yes' ? msgRequired : false;
console.log(value, required);
if (name === 'campaign') {
const required = value === mskStrCampaignId ? msgRequired : false;
rules.shadPlusRash.required = required;
rules.newTrack.required = required;
}
Expand Down