Verified Commit 73ba0b94 authored by Andrei Mondoc's avatar Andrei Mondoc Committed by Kevin Cristiano

accept api3 exception and return standardise api error data

Signed-off-by: Kevin Cristiano's avatarKevin Cristiano <kcristiano@kcristiano.com>
parent 05ecc92b
......@@ -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 );
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment