Add try catch around JSON parse of users meta values (https://github.com/woocommerce/woocommerce-admin/pull/6819)

* Add try catch around JSON parse of users meta values

* Add changelog
This commit is contained in:
louwie17 2021-04-16 17:31:59 -03:00 committed by GitHub
parent 89c19a4d20
commit 28d4c03ae0
3 changed files with 17 additions and 2 deletions

View File

@ -1,3 +1,7 @@
# Unreleased
- Fix parsing bad JSON string data in useUserPreferences hook. #6819
# 1.2.0
- Add management of persisted queries to navigation data store.

View File

@ -18,11 +18,21 @@ import { STORE_NAME } from './constants';
const getWooCommerceMeta = ( user ) => {
const wooMeta = user.woocommerce_meta || {};
const userData = mapValues( wooMeta, ( data ) => {
const userData = mapValues( wooMeta, ( data, key ) => {
if ( ! data || data.length === 0 ) {
return '';
}
return JSON.parse( data );
try {
return JSON.parse( data );
} catch ( e ) {
/* eslint-disable no-console */
console.error(
`Error parsing value '${ data }' for ${ key }`,
e.message
);
/* eslint-enable no-console */
return '';
}
} );
return userData;

View File

@ -104,6 +104,7 @@ Release and roadmap notes are available on the [WooCommerce Developers Blog](htt
- Fix: Pause inbox message "GivingFeedbackNotes" #6802
- Tweak: Sort the extension task list by completion status and allow toggling visibility. #6792
- Fix: Missed DB version number updates causing unnecessary upgrades. #6818
- Fix: Parsing bad JSON string data from user WooCommerce meta. #6819
== 2.2.0 3/30/2021 ==