Add specific exception in case of GPG encryption failing
This commit is contained in:
parent
900c2733e5
commit
bc998fbfa0
18
exceptions/MDMailerEncryptionFailedException.php
Normal file
18
exceptions/MDMailerEncryptionFailedException.php
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<?PHP
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception to be thrown
|
||||||
|
*/
|
||||||
|
final class MDMailerEncryptionFailedException {
|
||||||
|
/**
|
||||||
|
* Error message.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function errorMessage() {
|
||||||
|
//error message
|
||||||
|
return 'GPG encryption failed';
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -43,11 +43,16 @@ final class MDMailerHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($gpg->addsignkey(MD_CONF_EMAIL::PGP_ENC_KEY) === false) {
|
if ($gpg->addsignkey(MD_CONF_EMAIL::PGP_ENC_KEY) === false) {
|
||||||
throw new \Exception("Cannot set private key for GPG encryption");
|
throw new \MDMailerEncryptionFailedException("Cannot set private key for GPG encryption");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($msg = $gpg->encrypt($msg))) {
|
try {
|
||||||
throw new \Exception("Failed to sign and encrypt the message");
|
if (empty($msg = $gpg->encrypt($msg))) {
|
||||||
|
throw new \MDMailerEncryptionFailedException("Failed to sign and encrypt the message");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
throw new MDMailerEncryptionFailedException("Failed to sign and encrypt the message to " . $to);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $msg;
|
return $msg;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user