8000 Return 500 error code when query fails by leonidasmi · Pull Request #21864 · Yoast/wordpress-seo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Return 500 error code when query fails #21864

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 28, 2024

Conversation

leonidasmi
Copy link
Contributor
@leonidasmi leonidasmi commented Nov 27, 2024

Context

Summary

This PR can be summarized in the following changelog entry:

  • Enhances API endpoints by returning a 500 error code when queries fail.

Relevant technical choices:

Test instructions

Test instructions for the acceptance test before the PR gets merged

This PR can be acceptance tested by following these steps:

  • Add the following filter, to make the SEO score query fail:
add_filter( 'query', 'fail_seo_score_query' );
function fail_seo_score_query( $query ) {
	if ( strpos( $query, "SELECT COUNT(CASE WHEN I.primary_focus_keyword_score >= 0 AND I.primary_focus_keyword_score <= 40 THEN 1 END)" ) !== false ) {
        return false;
    }

    return $query;
}
  • Do a GET request to /wp-json/yoast/v1/seo_scores?contentType=post&taxonomy=category&term=1
  • Confirm that you get a 500 error code and a Score results not found error message
  • Within a minute from the GET request, remove the filter and retry
  • Confirm that you get correct results. Also confirm that you still get cacheUsed: true if you repeat the same request within a minute.
  • Do the same with readability scores:
    • The GET request should be to /wp-json/yoast/v1/readability_scores?contentType=post&taxonomy=category&term=1
    • The filter should be
add_filter( 'query', 'fail_readability_score_query' );
function fail_readability_score_query( $query ) {
	if ( strpos( $query, "COUNT(CASE WHEN I.readability_score = 0 AND I.estimated_reading_time_minutes IS NULL THEN 1 END) AS" ) !== false ) {
        return false;
    }

    return $query;
}

Note: Make sure you remove those filters after you're done testing.

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:

UI changes

  • This PR changes the UI in the plugin. I have added the 'UI change' label to this PR.

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.

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 https://github.com/Yoast/roadmap/issues/536

@leonidasmi leonidasmi added the changelog: non-user-facing Needs to be included in the 'Non-userfacing' category in the changelog label Nov 27, 2024
@coveralls
Copy link
coveralls commented Nov 27, 2024

Pull Request Test Coverage Report for Build 7a3614975ce615599e19259c66058a0017ad6786

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 24 (0.0%) changed or added relevant lines in 4 files are covered.
  • 1151 unchanged lines in 5 files lost coverage.
  • Overall coverage increased (+10.6%) to 54.108%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/dashboard/domain/score-results/score-results-not-found-exception.php 0 2 0.0%
src/dashboard/user-interface/scores/abstract-scores-route.php 0 2 0.0%
src/dashboard/infrastructure/score-results/readability-score-results/readability-score-results-collector.php 0 10 0.0%
src/dashboard/infrastructure/score-results/seo-score-results/seo-score-results-collector.php 0 10 0.0%
Files with Coverage Reduction New Missed Lines %
src/dashboard/infrastructure/score-results/readability-score-results/readability-score-results-collector.php 1 0.0%
src/dashboard/infrastructure/score-results/seo-score-results/seo-score-results-collector.php 1 0.0%
inc/class-wpseo-rank.php 2 98.21%
admin/class-meta-columns.php 101 25.76%
src/generated/container.php 1046 0.39%
Totals Coverage Status
Change from base Build ebe026d6d394f651e2f1f22f764ce7416bbb306c: 10.6%
Covered Lines: 29774
Relevant Lines: 55383

💛 - Coveralls

@leonidasmi leonidasmi added this to the feature/dash-phase-1 milestone Nov 27, 2024
@leonidasmi leonidasmi marked this pull request as ready for review November 27, 2024 10:29
Copy link
Contributor
@thijsoo thijsoo left a comment

Choose a reason for hiding this comment

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

I would throw the exception in the collector instead of the repo, and then handle that exception in the route to return the correct status code based on the error thrown in the code.

Copy link
Contributor
@thijsoo thijsoo left a comment

Choose a reason for hiding this comment

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

CR + ACC 👍

@thijsoo thijsoo merged commit fc39385 into feature/dash-phase-1 Nov 28, 2024
23 checks passed
@thijsoo thijsoo deleted the 536-enhance-backend-error-handling branch November 28, 2024 15:09
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.

4 participants
0