diff --git a/wp-rest/Controller/Base.php b/wp-rest/Controller/Base.php index 5115c490e7766d2e7b858765f56ba7f7d0a268ea..7546377e9e0973103beeaf4fff5e9789df04070c 100644 --- a/wp-rest/Controller/Base.php +++ b/wp-rest/Controller/Base.php @@ -88,13 +88,19 @@ abstract class Base extends \WP_REST_Controller implements Endpoint_Interface { * Wrapper for WP_Error. * * @since 0.1 - * @param string $message + * @param string|\CiviCRM_API3_Exception $error * @param mixed $data Error data * @return WP_Error $error */ - protected function civi_rest_error( $message, $data = [] ) { + protected function civi_rest_error( $error, $data = [] ) { - return new \WP_Error( 'civicrm_rest_api_error', $message, empty( $data ) ? [ 'status' => $this->authorization_status_code() ] : $data ); + if ( $error instanceof \CiviCRM_API3_Exception ) { + + return $error->getExtraParams(); + + } + + return new \WP_Error( 'civicrm_rest_api_error', $error, empty( $data ) ? [ 'status' => $this->authorization_status_code() ] : $data ); }