From f0abeed8ee833740187a6074638cad62f66ae694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Wed, 9 Mar 2022 15:10:59 +0100 Subject: [PATCH 1/5] Remove the catch clause from getEntityRecord and getEntityRecords --- packages/core-data/src/resolvers.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/core-data/src/resolvers.js b/packages/core-data/src/resolvers.js index 8368fd7a8afc5..05e75dc093d15 100644 --- a/packages/core-data/src/resolvers.js +++ b/packages/core-data/src/resolvers.js @@ -104,10 +104,6 @@ export const getEntityRecord = ( kind, name, key = '', query ) => async ( { const record = await apiFetch( { path } ); dispatch.receiveEntityRecords( kind, name, record, query ); - } catch ( error ) { - // We need a way to handle and access REST API errors in state - // Until then, catching the error ensures the resolver is marked as resolved. - // See similar implementation in `getEntityRecords()`. } finally { dispatch.__unstableReleaseStoreLock( lock ); } @@ -202,10 +198,6 @@ export const getEntityRecords = ( kind, name, query = {} ) => async ( { args: resolutionsArgs, } ); } - } catch ( error ) { - // We need a way to handle and access REST API errors in state - // Until then, catching the error ensures the resolver is marked as resolved. - // See similar implementation in `getEntityRecord()`. } finally { dispatch.__unstableReleaseStoreLock( lock ); } From 28a57a59034266656758884586685981c98443d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 10 Mar 2022 13:56:48 +0100 Subject: [PATCH 2/5] Add missing endpoints to the failing tests --- packages/editor/src/store/test/actions.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/editor/src/store/test/actions.js b/packages/editor/src/store/test/actions.js index 1b4454010ceaf..60d9a7405809d 100644 --- a/packages/editor/src/store/test/actions.js +++ b/packages/editor/src/store/test/actions.js @@ -83,6 +83,11 @@ describe( 'Post actions', () => { path.startsWith( `/wp/v2/posts/${ postId }` ) ) { return { ...post, ...data }; + } else if ( + method === 'GET' && + path.startsWith( '/wp/v2/types/post' ) + ) { + return {}; } throw { @@ -163,6 +168,13 @@ describe( 'Post actions', () => { } else if ( method === 'GET' ) { return []; } + } else if ( method === 'GET' ) { + if ( + path.startsWith( '/wp/v2/types/post' ) || + path.startsWith( '/wp/v2/posts/44' ) + ) { + return {}; + } } throw { @@ -239,6 +251,11 @@ describe( 'Post actions', () => { ...data, }; } + } else if ( + method === 'GET' && + path.startsWith( '/wp/v2/types/post' ) + ) { + return {}; } throw { From 927b7d277bc9c557dda97186d089b10e09a388c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 10 Mar 2022 16:58:52 +0100 Subject: [PATCH 3/5] Restore the catch clause with a deprecation notice --- packages/core-data/src/resolvers.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/core-data/src/resolvers.js b/packages/core-data/src/resolvers.js index 05e75dc093d15..af58dccc95cef 100644 --- a/packages/core-data/src/resolvers.js +++ b/packages/core-data/src/resolvers.js @@ -8,6 +8,7 @@ import { find, includes, get, compact, uniq } from 'lodash'; */ import { addQueryArgs } from '@wordpress/url'; import apiFetch from '@wordpress/api-fetch'; +import deprecated from '@wordpress/deprecated'; /** * Internal dependencies @@ -104,6 +105,17 @@ export const getEntityRecord = ( kind, name, key = '', query ) => async ( { const record = await apiFetch( { path } ); dispatch.receiveEntityRecords( kind, name, record, query ); + } catch ( error ) { + deprecated( + 'Wordpress silently hid the errors for getEntityRecord and getEntityRecords resolvers. ' + + 'These resolved even if error occurred. This has changed in 6.0 and starting 6.1 the errors ' + + 'will be thrown.', + { + since: '6.0', + } + ); + // eslint-disable-next-line no-console + console.error( error ); } finally { dispatch.__unstableReleaseStoreLock( lock ); } @@ -198,6 +210,17 @@ export const getEntityRecords = ( kind, name, query = {} ) => async ( { args: resolutionsArgs, } ); } + } catch ( error ) { + deprecated( + 'Wordpress silently hid the errors for getEntityRecord and getEntityRecords resolvers. ' + + 'These resolved even if error occurred. This has changed in 6.0 and starting 6.1 the errors ' + + 'will be thrown.', + { + since: '6.0', + } + ); + // eslint-disable-next-line no-console + console.error( error ); } finally { dispatch.__unstableReleaseStoreLock( lock ); } From e8b809f68ac6d03896b093132fcafaa44146b093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 10 Mar 2022 17:03:51 +0100 Subject: [PATCH 4/5] Document the changes in unit tests --- packages/editor/src/store/test/actions.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/editor/src/store/test/actions.js b/packages/editor/src/store/test/actions.js index 60d9a7405809d..6931f1cbbfde9 100644 --- a/packages/editor/src/store/test/actions.js +++ b/packages/editor/src/store/test/actions.js @@ -84,6 +84,8 @@ describe( 'Post actions', () => { ) { return { ...post, ...data }; } else if ( + // This URL is requested by the actions dispatched in this test. + // They are safe to ignore and are only listed here to avoid triggeringan error. method === 'GET' && path.startsWith( '/wp/v2/types/post' ) ) { @@ -169,9 +171,11 @@ describe( 'Post actions', () => { return []; } } else if ( method === 'GET' ) { + // These URLs are requested by the actions dispatched in this test. + // They are safe to ignore and are only listed here to avoid triggeringan error. if ( path.startsWith( '/wp/v2/types/post' ) || - path.startsWith( '/wp/v2/posts/44' ) + path.startsWith( `/wp/v2/posts/${ postId }` ) ) { return {}; } @@ -251,6 +255,8 @@ describe( 'Post actions', () => { ...data, }; } + // This URL is requested by the actions dispatched in this test. + // They are safe to ignore and are only listed here to avoid triggeringan error. } else if ( method === 'GET' && path.startsWith( '/wp/v2/types/post' ) From 56b15ed72be4dfb298be11357642de8c17641555 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 11 Mar 2022 10:35:57 +0100 Subject: [PATCH 5/5] Remove the deprecation notice and the catch clause --- packages/core-data/src/resolvers.js | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/packages/core-data/src/resolvers.js b/packages/core-data/src/resolvers.js index af58dccc95cef..05e75dc093d15 100644 --- a/packages/core-data/src/resolvers.js +++ b/packages/core-data/src/resolvers.js @@ -8,7 +8,6 @@ import { find, includes, get, compact, uniq } from 'lodash'; */ import { addQueryArgs } from '@wordpress/url'; import apiFetch from '@wordpress/api-fetch'; -import deprecated from '@wordpress/deprecated'; /** * Internal dependencies @@ -105,17 +104,6 @@ export const getEntityRecord = ( kind, name, key = '', query ) => async ( { const record = await apiFetch( { path } ); dispatch.receiveEntityRecords( kind, name, record, query ); - } catch ( error ) { - deprecated( - 'Wordpress silently hid the errors for getEntityRecord and getEntityRecords resolvers. ' + - 'These resolved even if error occurred. This has changed in 6.0 and starting 6.1 the errors ' + - 'will be thrown.', - { - since: '6.0', - } - ); - // eslint-disable-next-line no-console - console.error( error ); } finally { dispatch.__unstableReleaseStoreLock( lock ); } @@ -210,17 +198,6 @@ export const getEntityRecords = ( kind, name, query = {} ) => async ( { args: resolutionsArgs, } ); } - } catch ( error ) { - deprecated( - 'Wordpress silently hid the errors for getEntityRecord and getEntityRecords resolvers. ' + - 'These resolved even if error occurred. This has changed in 6.0 and starting 6.1 the errors ' + - 'will be thrown.', - { - since: '6.0', - } - ); - // eslint-disable-next-line no-console - console.error( error ); } finally { dispatch.__unstableReleaseStoreLock( lock ); }