Skip to content

Commit

Permalink
accept api3 exception and return standardise api error data
Browse files Browse the repository at this point in the history
  • Loading branch information
mecachisenros committed Aug 24, 2019
1 parent d2dcfd2 commit 7715594
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Controller/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,19 @@ protected function authorization_status_code() {
* 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 );

}

Expand Down

0 comments on commit 7715594

Please sign in to comment.