Add specific exception in case of GPG encryption failing

This commit is contained in:
jrenslin committed 2023-11-21 01:44:19 +01:00
1 parent 900c2733e5
commit bc998fbfa0
2 files changed
+26 -3

No files matched your search

+8 -3
View File
@@ -43,11 +43,16 @@ public static function pgp_encrypt(string $to, string $msg):string {
}
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))) {
throw new \Exception("Failed to sign and encrypt the message");
try {
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;