create custom exceptions
This commit is contained in:
parent
6606d09dce
commit
72bfa3fb2c
3 changed files with 93 additions and 0 deletions
43
CRM/Twingle/Exceptions/BaseException.php
Normal file
43
CRM/Twingle/Exceptions/BaseException.php
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use CRM_Twingle_ExtensionUtil as E;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple custom exception class that indicates a problem within a class
|
||||||
|
* of the Twingle API extension.
|
||||||
|
*/
|
||||||
|
class CRM_Twingle_Exceptions_BaseException extends Exception {
|
||||||
|
|
||||||
|
private string $error_code;
|
||||||
|
private string $log_message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BaseException Constructor
|
||||||
|
* @param string $message
|
||||||
|
* Error message
|
||||||
|
* @param string $error_code
|
||||||
|
* A meaningful error code
|
||||||
|
*/
|
||||||
|
public function __construct(string $message = '', string $error_code = '') {
|
||||||
|
parent::__construct($message, 1);
|
||||||
|
$this->log_message = !empty($message) ? E::LONG_NAME . ': ' . $message : '';
|
||||||
|
$this->error_code = $error_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the error message, but with the extension name prefixed.
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getLogMessage() {
|
||||||
|
return $this->log_message;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the error code.
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getErrorCode() {
|
||||||
|
return $this->error_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
CRM/Twingle/Exceptions/ProfileException.php
Normal file
16
CRM/Twingle/Exceptions/ProfileException.php
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple custom exception that indicates a problem within the
|
||||||
|
* CRM_Twingle_Profile class
|
||||||
|
*/
|
||||||
|
class CRM_Twingle_Exceptions_ProfileException extends CRM_Twingle_Exceptions_BaseException {
|
||||||
|
|
||||||
|
public const ERROR_CODE_PROFILE_NOT_FOUND = 'profile_not_found';
|
||||||
|
public const ERROR_CODE_DEFAULT_PROFILE_NOT_FOUND = 'default_profile_not_found';
|
||||||
|
public const ERROR_CODE_COULD_NOT_SAVE_PROFILE = 'could_not_save_profile';
|
||||||
|
public const ERROR_CODE_COULD_NOT_RESET_PROFILE = 'could_not_reset_profile';
|
||||||
|
public const ERROR_CODE_COULD_NOT_DELETE_PROFILE = 'could_not_delete_profile';
|
||||||
|
public const ERROR_CODE_UNKNOWN_PROFILE_ATTRIBUTE = 'unknown_profile_attribute';
|
||||||
|
|
||||||
|
}
|
34
CRM/Twingle/Exceptions/ProfileValidationError.php
Normal file
34
CRM/Twingle/Exceptions/ProfileValidationError.php
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple custom error indicating a problem with the validation of the
|
||||||
|
* CRM_Twingle_Profile
|
||||||
|
*/
|
||||||
|
class CRM_Twingle_Exceptions_ProfileValidationError extends CRM_Twingle_Exceptions_BaseException {
|
||||||
|
|
||||||
|
private string $affected_field_name;
|
||||||
|
public const ERROR_CODE_PROFILE_VALIDATION_FAILED = 'profile_validation_failed';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ProfileValidationError Constructor
|
||||||
|
* @param string $affected_field_name
|
||||||
|
* The name of the profile field which caused the exception
|
||||||
|
* @param string $message
|
||||||
|
* Error message
|
||||||
|
* @param string $error_code
|
||||||
|
* A meaningful error code
|
||||||
|
*/
|
||||||
|
public function __construct(string $affected_field_name, string $message = '', string $error_code = '') {
|
||||||
|
parent::__construct($message, 1);
|
||||||
|
$this->affected_field_name = $affected_field_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of the profile field that caused the exception.
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getAffectedFieldName() {
|
||||||
|
return $this->affected_field_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue