[wp-trac] [WordPress Trac] #41370: REST API: Attempting to create an existing term yields HTTP 500

WordPress Trac noreply at wordpress.org
Sun Sep 17 05:08:27 UTC 2017


#41370: REST API: Attempting to create an existing term yields HTTP 500
-------------------------------------------------+-------------------------
 Reporter:  jnylen0                              |       Owner:
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  Future
Component:  REST API                             |  Release
 Severity:  normal                               |     Version:  4.7
 Keywords:  needs-unit-tests good-first-bug      |  Resolution:
  needs-testing                                  |     Focuses:  rest-api
-------------------------------------------------+-------------------------

Comment (by guzzilar):

 Hi @alibasheer
 Sorry, I still can't find the way to patch code in (also new here too 😁).
 But from your patch, if you want to make it to be `400` status code, you
 can simply add `status` array in the first param of `$term->add_data();`

 So from

 {{{#!php
 <?php

 $term->add_data( $existing_term->term_id, 'term_exists' );
 }}}


 Could be

 {{{#!php
 <?php

 $term->add_data( array( 'status' => 400, 'existing_term_id' =>
 $existing_term->term_id ), 'term_exists' );
 }}}

 You will get an output

 {{{
 {
     "code": "term_exists",
     "message": "A term with the name provided already exists with this
 parent.",
     "data": {
         "status": 400,
         "existing_term_id": 1
     }
 }
 }}}

 with status `400 Bad Request`.

 Sorry that I can't help patch it by myself.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/41370#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list