Skip to content

Server error message is replaced by a generic one when creating a template part, overlay or navigation menu fails #87107

Open

Description

@Mayank-Tripathi32

Description

saveEntityRecord( …, { throwOnError: true } ) rethrows what apiFetch rejected with. For a REST API error that is a plain object ({ code, message, data }), not an Error. A few callers check error instanceof Error before reading message, so that check is always false for a REST error and the server's reason is thrown away for a generic message.

For template parts, the check came in with #65390 when the modal moved to TypeScript (before that it read error.message directly). The overlay selector copied the same check.

Affected:

  • packages/patterns/src/components/create-template-part-modal/index.tsx: always shows "An error occurred while creating the template part."
  • packages/block-library/src/navigation/edit/overlay-template-part-selector.jsx (creating an overlay from the Navigation block): always shows "An error occurred while creating the overlay."
  • routes/navigation-list/add-navigation.tsx: shows "Unable to create navigation menu: Unknown error", where "Unknown error" is also not translatable.
  • routes/guidelines/components/guideline-actions-section.tsx: importing shows "We ran into a problem importing your guidelines: Unknown error" when a save or delete fails on the server.

Step-by-step reproduction instructions

  1. Add this as a mu-plugin to force a REST error:
<?php
add_filter(
	'rest_request_before_callbacks',
	function ( $response, $handler, $request ) {
		if ( 'POST' === $request->get_method() && str_starts_with( $request->get_route(), '/wp/v2/template-parts' ) ) {
			return new WP_Error( 'test_error', 'Template parts are read-only on this site.', array( 'status' => 403 ) );
		}
		return $response;
	},
	10,
	3
);
  1. Go to Appearance > Editor > Patterns.
  2. Click "Add Pattern" and choose "Add Template Part".
  3. Enter a name and click "Add".

Expected: the snackbar says "Template parts are read-only on this site."

Actual: the snackbar says "An error occurred while creating the template part."

The same happens for a real server error, e.g. a user without permission or a failed request.

Screenshots, screen recording, code snippet

before-trunk-template-part

Environment info

  • Gutenberg trunk (ce0be3c), wp-env, Emptytheme, Chrome

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

[Type] BugAn existing feature does not function as intended

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions