Skip to content

Commit

Permalink
Fix exception handling in v2 update_additional_fields_for_object REST…
Browse files Browse the repository at this point in the history
… API calls
  • Loading branch information
manospsyx committed Jan 10, 2018
1 parent a94ef8d commit 009a21a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions includes/abstracts/abstract-wc-rest-crud-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,15 @@ public function create_item( $request ) {
return $object;
}

$this->update_additional_fields_for_object( $object, $request );
try {
$this->update_additional_fields_for_object( $object, $request );
} catch ( WC_Data_Exception $e ) {
$object->delete();
return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
} catch ( WC_REST_Exception $e ) {
$object->delete();
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
}

/**
* Fires after a single object is created or updated via the REST API.
Expand Down Expand Up @@ -231,7 +239,13 @@ public function update_item( $request ) {
return $object;
}

$this->update_additional_fields_for_object( $object, $request );
try {
$this->update_additional_fields_for_object( $object, $request );
} catch ( WC_Data_Exception $e ) {
return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
} catch ( WC_REST_Exception $e ) {
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
}

/**
* Fires after a single object is created or updated via the REST API.
Expand Down

0 comments on commit 009a21a

Please sign in to comment.