From 59c31d2d740f9bbd5792aa81086cb9616576392b Mon Sep 17 00:00:00 2001 From: Rachel Baker Date: Sun, 3 Dec 2017 19:08:23 +0000 Subject: [PATCH] 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. Fixes #42781. See #41370. git-svn-id: https://develop.svn.wordpress.org/trunk@42354 602fd350-edb4-49c9-b593-d223f7449a82 --- .../rest-api/endpoints/class-wp-rest-terms-controller.php | 2 +- tests/phpunit/tests/rest-api/rest-categories-controller.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php index 7c62c34fe8..5a844bdfce 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php @@ -419,7 +419,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; diff --git a/tests/phpunit/tests/rest-api/rest-categories-controller.php b/tests/phpunit/tests/rest-api/rest-categories-controller.php index 4c1152133e..4161a5bd69 100644 --- a/tests/phpunit/tests/rest-api/rest-categories-controller.php +++ b/tests/phpunit/tests/rest-api/rest-categories-controller.php @@ -702,7 +702,7 @@ class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcas $request->set_param( 'name', 'Existing' ); $response = $this->server->dispatch( $request ); - $this->assertEquals( 409, $response->get_status() ); + $this->assertEquals( 400, $response->get_status() ); $data = $response->get_data(); $this->assertEquals( 'term_exists', $data['code'] ); $this->assertEquals( $existing_id, (int) $data['data']['term_id'] );