REST API: Correct HTTP status code in error for requests to create a duplicate term.

The 409 error code is intended for situations where it is expected that the user will resolve the conflict and resubmit the same request. We use 400 error codes for other routes when a duplicate request is made. The 400 status code tells the user they need to modify their request for it to be successful.

Props shooper.
Merges [42354] to the 5.0 branch.
Fixes #42781. See #41370.

Built from https://develop.svn.wordpress.org/branches/5.0@43756


git-svn-id: http://core.svn.wordpress.org/branches/5.0@43585 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
danielbachhuber 2018-10-18 20:32:27 +00:00
parent 8023795f7d
commit 699bf044ef
2 changed files with 2 additions and 2 deletions

View File

@ -418,7 +418,7 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
if ( $term_id = $term->get_error_data( 'term_exists' ) ) {
$existing_term = get_term( $term_id, $this->taxonomy );
$term->add_data( $existing_term->term_id, 'term_exists' );
$term->add_data( array( 'status' => 409, 'term_id' => $term_id ) );
$term->add_data( array( 'status' => 400, 'term_id' => $term_id ) );
}
return $term;

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.0-alpha-43755';
$wp_version = '5.0-alpha-43756';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.