Skip to content

Commit

Permalink
Fix console warning by improving error handling in Nav block classic …
Browse files Browse the repository at this point in the history
…menu conversion (#52591)

* use the same create hook for classic import

* Remove redundant arg to hook

* Add option to throw on error rather than default to doing so

---------

Co-authored-by: Andrei Draganescu <andrei.draganescu@automattic.com>
  • Loading branch information
getdave and draganescu authored Jul 13, 2023
1 parent 6ff5f1c commit 800cd8c
Showing 1 changed file with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export const CLASSIC_MENU_CONVERSION_IDLE = 'idle';
// do not import the same classic menu twice.
let classicMenuBeingConvertedId = null;

function useConvertClassicToBlockMenu( createNavigationMenu ) {
function useConvertClassicToBlockMenu(
createNavigationMenu,
{ throwOnError = false } = {}
) {
const registry = useRegistry();
const { editEntityRecord } = useDispatch( coreStore );

Expand Down Expand Up @@ -149,19 +152,21 @@ function useConvertClassicToBlockMenu( createNavigationMenu ) {
classicMenuBeingConvertedId = null;

// Rethrow error for debugging.
throw new Error(
sprintf(
// translators: %s: the name of a menu (e.g. Header navigation).
__( `Unable to create Navigation Menu "%s".` ),
menuName
),
{
cause: err,
}
);
if ( throwOnError ) {
throw new Error(
sprintf(
// translators: %s: the name of a menu (e.g. Header navigation).
__( `Unable to create Navigation Menu "%s".` ),
menuName
),
{
cause: err,
}
);
}
} );
},
[ convertClassicMenuToBlockMenu ]
[ convertClassicMenuToBlockMenu, throwOnError ]
);

return {
Expand Down

0 comments on commit 800cd8c

Please sign in to comment.