Skip to content

Adds error handling in backend endpoints#22742

Merged
vraja-pro merged 7 commits intofeature/task-listfrom
865-backend-error-handling
Nov 24, 2025
Merged

Adds error handling in backend endpoints#22742
vraja-pro merged 7 commits intofeature/task-listfrom
865-backend-error-handling

Conversation

@leonidasmi
Copy link
Copy Markdown
Contributor

@leonidasmi leonidasmi commented Nov 21, 2025

Context

Summary

This PR can be summarized in the following changelog entry:

  • Add error handling in backend endpoints.

Relevant technical choices:

  • We skip error handling in Abstract_Post_Type_Tasks because we add proper post types when we build instances, so it wouldn't be testable anyway.

Test instructions

Test instructions for the acceptance test before the PR gets merged

This PR can be acceptance tested by following these steps:

Failure to complete the llms.txt task:

  • Add the following snippet (this will force failure to turn the llms.txt feature from disabled to enabled - remember to remove it afterwards)
function custom_update_option_wpseo( $value, $old_value, $option ) {
    return $old_value;
}
add_action( 'pre_update_option_wpseo', 'custom_update_option_wpseo', 10, 3 );
  • Run the POST request: http://dev.local/wp-json/yoast/v1/complete_task?options[task]=enable-llms-txt
  • Confirm that you get the following 400 response:
    "success": false,
    "error": "Failed to enable llms.txt option."
}

Failure to complete the delete Hello World task:

  • Add the following snippet (this will force failure to delete any posts - remember to remove it afterwards)
function custom_pre_delete_post( $check, $post, $force_delete ) {
    return false;
}
add_filter( 'pre_delete_post', 'custom_pre_delete_post', 10, 3 );
  • Run the POST request: http://dev.local/wp-json/yoast/v1/complete_task?options[task]=delete-hello-world
  • Confirm that you get the following 400 response:
    "success": false,
    "error": "Failed to delete the Hello World post."
}

Failure to get tasks:

  • Add the following snippet (this will force failure to get any tasks - remember to remove it afterwards)
add_filter( 'wpseo_task_list_post_type_tasks', 'custom_task_list_post_type_tasks', 10, 3 );

function custom_task_list_post_type_tasks( $post_type_tasks ) {
    return array_merge( $post_type_tasks, [ 'new-task' => [ 'new-task' ] ] );
}
  • Run the GET request: http://dev.local/wp-json/yoast/v1/get_tasks
  • Confirm that you get the following 400 response:
{
    "success": false,
    "error": "Added invalid post type task"
}

Relevant test scenarios

  • Changes should be tested with the browser console open
  • Changes should be tested on different posts/pages/taxonomies/custom post types/custom taxonomies
  • Changes should be tested on different editors (Default Block/Gutenberg/Classic/Elementor/other)
  • Changes should be tested on different browsers
  • Changes should be tested on multisite

Test instructions for QA when the code is in the RC

  • QA should use the same steps as above.

Impact check

This PR affects the following parts of the plugin, which may require extra testing:

Other environments

  • This PR also affects Shopify. I have added a changelog entry starting with [shopify-seo], added test instructions for Shopify and attached the Shopify label to this PR.

Documentation

  • I have written documentation for this change. For example, comments in the Relevant technical choices, comments in the code, documentation on Confluence / shared Google Drive / Yoast developer portal, or other.

Quality assurance

  • I have tested this code to the best of my abilities.
  • During testing, I had activated all plugins that Yoast SEO provides integrations for.
  • I have added unit tests to verify the code works as intended.
  • If any part of the code is behind a feature flag, my test instructions also cover cases where the feature flag is switched off.
  • I have written this PR in accordance with my team's definition of done.
  • I have checked that the base branch is correctly set.
  • I have ran grunt build:images and commited the results, if my PR introduces new images or SVGs.

Innovation

  • No innovation project is applicable for this PR.
  • This PR falls under an innovation project. I have attached the innovation label.
  • I have added my hours to the WBSO document.

Fixes #

@coveralls
Copy link
Copy Markdown

coveralls commented Nov 21, 2025

Pull Request Test Coverage Report for Build a266586101d3fb2cb541022854364f3975b101ea

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 17 (0.0%) changed or added relevant lines in 6 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.01%) to 52.659%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/task-list/domain/exceptions/complete-hello-world-task-exception.php 0 2 0.0%
src/task-list/domain/exceptions/complete-llms-task-exception.php 0 2 0.0%
src/task-list/domain/exceptions/invalid-post-type-tasks-exception.php 0 2 0.0%
src/task-list/application/tasks/delete-hello-world.php 0 3 0.0%
src/task-list/application/tasks/enable-llms-txt.php 0 3 0.0%
src/task-list/infrastructure/register-post-type-tasks-integration.php 0 5 0.0%
Files with Coverage Reduction New Missed Lines %
src/task-list/application/tasks/delete-hello-world.php 1 0.0%
Totals Coverage Status
Change from base Build bd8c0cc116673dddcac4292ae8ffe15ebc7d6c6c: -0.01%
Covered Lines: 31811
Relevant Lines: 60615

💛 - Coveralls

@leonidasmi leonidasmi added the changelog: non-user-facing Needs to be included in the 'Non-userfacing' category in the changelog label Nov 21, 2025
@leonidasmi leonidasmi changed the title Throw exception when failing to enable the llms.txt option Adds error handling in backend endpoints Nov 24, 2025
@leonidasmi leonidasmi marked this pull request as ready for review November 24, 2025 09:33
Copy link
Copy Markdown
Contributor

@vraja-pro vraja-pro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR & AC ✅

@vraja-pro vraja-pro added this to the feature/task-list milestone Nov 24, 2025
@vraja-pro vraja-pro merged commit f25d8d9 into feature/task-list Nov 24, 2025
27 checks passed
@vraja-pro vraja-pro deleted the 865-backend-error-handling branch November 24, 2025 12:51
@leonidasmi leonidasmi mentioned this pull request Nov 27, 2025
18 tasks
@leonidasmi leonidasmi modified the milestones: feature/task-list, 26.6 Dec 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog: non-user-facing Needs to be included in the 'Non-userfacing' category in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants