From b9b04278882bd1ec0a2413266638d4ee5ebfa267 Mon Sep 17 00:00:00 2001 From: Andrei Mondoc <andreimondoc@gmail.com> Date: Thu, 29 Aug 2019 15:28:42 +0100 Subject: [PATCH] accept api3 exception and return standardise api error data Signed-off-by: Kevin Cristiano <kcristiano@kcristiano.com> --- wp-rest/Controller/Base.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/wp-rest/Controller/Base.php b/wp-rest/Controller/Base.php index 5115c490e7..7546377e9e 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 ); } -- GitLab