create custom exceptions

This commit is contained in:
Marc Michalsky 2023-08-03 14:52:30 +02:00 committed by Jens Schuppe
parent 7a751e92bf
commit 43be624bf6
5 changed files with 127 additions and 16 deletions

View file

@ -16,6 +16,8 @@
declare(strict_types = 1);
use CRM_Twingle_ExtensionUtil as E;
use CRM_Twingle_Exceptions_ProfileException as ProfileException;
use CRM_Twingle_Exceptions_ProfileValidationError as ProfileValidationError;
/**
* Profiles define how incoming submissions from the Twingle API are
@ -142,12 +144,15 @@ class CRM_Twingle_Profile {
* @param string $attribute_name
* @param mixed $value
*
* @throws \Exception
* @throws \CRM_Twingle_Exceptions_ProfileException
* When the attribute name is not known.
*/
public function setAttribute($attribute_name, $value) {
if (!in_array($attribute_name, self::allowedAttributes())) {
throw new Exception(E::ts('Unknown attribute %1.', [1 => $attribute_name]));
throw new ProfileException(
E::ts('Unknown attribute %1.', [1 => $attribute_name]),
ProfileException::ERROR_CODE_UNKNOWN_PROFILE_ATTRIBUTE
);
}
// TODO: Check if value is acceptable.
$this->data[$attribute_name] = $value;
@ -430,6 +435,7 @@ class CRM_Twingle_Profile {
* Get the stats (access_count, last_access) for all twingle profiles
*
* @return CRM_Twingle_Profile[]
* @throws \Civi\Core\Exception\DBQueryException
*/
public static function getProfileStats() {
$stats = [];