Skip to content

Commit

Permalink
[core-data] Do not suppress errors in the getEntityRecord and getEnti…
Browse files Browse the repository at this point in the history
…tyRecords 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
  • Loading branch information
adamziel authored Mar 14, 2022
1 parent e313030 commit e4dd93d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
8 changes: 0 additions & 8 deletions packages/core-data/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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 );
}
Expand Down
23 changes: 23 additions & 0 deletions packages/editor/src/store/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit e4dd93d

Please sign in to comment.