Skip to content

Commit

Permalink
Add option to throw on error rather than default to doing so
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave authored and scruffian committed Jul 13, 2023
1 parent 1139a90 commit fb724d2
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 fb724d2

Please sign in to comment.