From e4dd93d70ce8b7c4deab25daac4fada41f6d1b25 Mon Sep 17 00:00:00 2001 From: Adam Zielinski Date: Mon, 14 Mar 2022 12:35:11 +0100 Subject: [PATCH] [core-data] Do not suppress errors in the getEntityRecord and getEntityRecords resolvers (#39317) * Remove the catch clause from getEntityRecord and getEntityRecords * Add missing endpoints to the failing tests * Restore the catch clause with a deprecation notice * Document the changes in unit tests * Remove the deprecation notice and the catch clause --- packages/core-data/src/resolvers.js | 8 -------- packages/editor/src/store/test/actions.js | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/packages/core-data/src/resolvers.js b/packages/core-data/src/resolvers.js index c46b4b4314827..fda58b2fe9ea8 100644 --- a/packages/core-data/src/resolvers.js +++ b/packages/core-data/src/resolvers.js @@ -107,10 +107,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 ); } @@ -205,10 +201,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 ); } diff --git a/packages/editor/src/store/test/actions.js b/packages/editor/src/store/test/actions.js index 1b4454010ceaf..6931f1cbbfde9 100644 --- a/packages/editor/src/store/test/actions.js +++ b/packages/editor/src/store/test/actions.js @@ -83,6 +83,13 @@ describe( 'Post actions', () => { path.startsWith( `/wp/v2/posts/${ postId }` ) ) { 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' ) + ) { + return {}; } throw { @@ -163,6 +170,15 @@ describe( 'Post actions', () => { } else if ( method === 'GET' ) { 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/${ postId }` ) + ) { + return {}; + } } throw { @@ -239,6 +255,13 @@ 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' ) + ) { + return {}; } throw {