Make WordPress Core

Changeset 42354


Ignore:
Timestamp:
12/03/2017 07:08:23 PM (6 years ago)
Author:
rachelbaker
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php

    r42350 r42354  
    420420                $existing_term = get_term( $term_id, $this->taxonomy );
    421421                $term->add_data( $existing_term->term_id, 'term_exists' );
    422                 $term->add_data( array( 'status' => 409, 'term_id' => $term_id ) );
     422                $term->add_data( array( 'status' => 400, 'term_id' => $term_id ) );
    423423            }
    424424
  • trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php

    r42350 r42354  
    703703
    704704        $response = $this->server->dispatch( $request );
    705         $this->assertEquals( 409, $response->get_status() );
     705        $this->assertEquals( 400, $response->get_status() );
    706706        $data = $response->get_data();
    707707        $this->assertEquals( 'term_exists', $data['code'] );
Note: See TracChangeset for help on using the changeset viewer.