diff --git a/CRM/MembershipExtras/Form/RecurringContribution/SwitchMembershipType.php b/CRM/MembershipExtras/Form/RecurringContribution/SwitchMembershipType.php index 52a01f5a..5e59db56 100644 --- a/CRM/MembershipExtras/Form/RecurringContribution/SwitchMembershipType.php +++ b/CRM/MembershipExtras/Form/RecurringContribution/SwitchMembershipType.php @@ -117,8 +117,10 @@ public function postProcess() { ); } catch (Exception $e) { + $errorMessage = $e->getMessage(); + $this->replaceExceptionMessagesWithHumanReadableContent($errorMessage); CRM_Core_Session::setStatus( - ts('The membership type could not be changed: ') . $e->getMessage(), + ts('The membership type could not be changed. Error reason: ') . $e->getMessage(), ts('Changing Membership Type'), 'error' ); @@ -140,4 +142,18 @@ private function getOneOffFeeParams($submittedValues) { ]; } + /** + * Replaces some of the exception messages thrown + * when submitting this form with more readable + * content. + * + * @param string $errorMessage + * @return void + */ + private function replaceExceptionMessagesWithHumanReadableContent(&$errorMessage) { + if (strpos($errorMessage, 'The membership cannot be saved because the status cannot be calculated') !== FALSE) { + $errorMessage = 'There is no valid membership status available for the given membership dates.'; + } + } + }