handle any errors thrown in survey handleSubmit

This commit is contained in:
Keith Grant
2020-03-20 10:53:59 -07:00
parent 564012b2c8
commit 56d31fec77
2 changed files with 19 additions and 20 deletions

View File

@@ -9,6 +9,7 @@ export default function SurveyQuestionAdd({ survey, updateSurvey }) {
const match = useRouteMatch(); const match = useRouteMatch();
const handleSubmit = async question => { const handleSubmit = async question => {
try {
if (survey.spec?.some(q => q.variable === question.variable)) { if (survey.spec?.some(q => q.variable === question.variable)) {
setFormError( setFormError(
new Error( new Error(
@@ -17,7 +18,6 @@ export default function SurveyQuestionAdd({ survey, updateSurvey }) {
); );
return; return;
} }
try {
const newSpec = survey.spec ? survey.spec.concat(question) : [question]; const newSpec = survey.spec ? survey.spec.concat(question) : [question];
await updateSurvey(newSpec); await updateSurvey(newSpec);
history.push(match.url.replace('/add', '')); history.push(match.url.replace('/add', ''));

View File

@@ -21,11 +21,11 @@ export default function SurveyQuestionEdit({ survey, updateSurvey }) {
}; };
const handleSubmit = async formData => { const handleSubmit = async formData => {
try {
if ( if (
formData.variable !== question.variable && formData.variable !== question.variable &&
survey.spec.find(q => q.variable === formData.variable) survey.spec.find(q => q.variable === formData.variable)
) { ) {
debugger;
setFormError( setFormError(
new Error( new Error(
`Survey already contains a question with variable named “${formData.variable}` `Survey already contains a question with variable named “${formData.variable}`
@@ -33,7 +33,6 @@ export default function SurveyQuestionEdit({ survey, updateSurvey }) {
); );
return; return;
} }
try {
const questionIndex = survey.spec.findIndex( const questionIndex = survey.spec.findIndex(
q => q.variable === match.params.variable q => q.variable === match.params.variable
); );