Skip to content

Commit 0598803

Browse files
committed
fix: try catch on json.parse
1 parent a5a84a3 commit 0598803

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/config/italiaConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ export default function applyConfig(voltoConfig) {
489489
},
490490
form: {
491491
...config.blocks.blocksConfig.form,
492-
enableConditionalFields: false,
492+
enableConditionalFields: true,
493493
enableDatatableView: false,
494494
},
495495
};

src/customizations/volto-form-block/components/View.jsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -356,17 +356,22 @@ const View = ({ data, id, path }) => {
356356
});
357357
}
358358
} else if (submitResults?.error) {
359-
let errorDescription = `${
360-
JSON.parse(submitResults.error.response?.text ?? '{}')?.message
361-
}`;
362-
363359
//CUSTOM: handle field errors coming from backend
364-
365360
let fieldsErrors = [];
366-
if (errorDescription.startsWith('[')) {
367-
fieldsErrors = JSON.parse(
368-
errorDescription.replaceAll('"', '\\"').replaceAll("'", '"'),
369-
);
361+
let errorDescription = '';
362+
363+
try {
364+
errorDescription = `${
365+
JSON.parse(submitResults.error.response?.text ?? '{}')?.message
366+
}`;
367+
368+
if (errorDescription.startsWith('[')) {
369+
fieldsErrors = JSON.parse(
370+
errorDescription.replaceAll('"', '\\"').replaceAll("'", '"'),
371+
);
372+
}
373+
} catch (e) {
374+
errorDescription = 'Error parsing error response';
370375
}
371376

372377
// fieldsErrors = [

0 commit comments

Comments
 (0)