Skip to content
Snippets Groups Projects
Verified Commit 69ca92ae authored by Andrei Mondoc's avatar Andrei Mondoc Committed by Kevin Cristiano
Browse files

accept api3 exception and return standardise api error data

parent 859bb268
No related branches found
No related tags found
No related merge requests found
......@@ -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 );
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment