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
This commit is contained in:
parent
0f0db92b0d
commit
59c31d2d74
|
@ -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;
|
||||
|
|
|
@ -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'] );
|
||||
|
|
Loading…
Reference in New Issue