Skip to content

Commit 85e0edd

Browse files
committed
develop/v0.1.0: Updated the exception in the Trait
1 parent 9650075 commit 85e0edd

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/Traits/HasEncryptedAttributes.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Wazza\DbEncrypt\Http\Controllers\DbEncryptController;
66
use Wazza\DbEncrypt\Models\EncryptedAttributes;
77
use Wazza\DbEncrypt\Helper\Encryptor;
8+
use Illuminate\Support\Facades\Log;
89

910
/**
1011
* Include this trait in your model to enable database encryption functionality.
@@ -57,7 +58,11 @@ public function loadEncryptedAttributes(): void
5758
$dnEncryptController->setModel($this);
5859
$dnEncryptController->decrypt();
5960
} catch (\Throwable $e) {
60-
// Optionally log or handle decryption errors
61+
// Log the error with context, but never log sensitive values
62+
Log::error('DB Encrypt: Failed to decrypt attributes for model ' . get_class($this) . ' (ID: ' . ($this->getKey() ?? 'n/a') . '): ' . $e->getMessage());
63+
64+
// Optionally, throw a custom exception for the application layer
65+
throw new \RuntimeException('Failed to decrypt encrypted attributes for this model. Please check the logs for details.', 0, $e);
6166
}
6267
}
6368

@@ -102,7 +107,11 @@ public function saveEncryptedAttributes(): void
102107
$dnEncryptController->encryptProperty($prop);
103108
}
104109
} catch (\Throwable $e) {
105-
// Optionally log or handle encryption errors
110+
// Log the error with context, but never log sensitive values
111+
Log::error('DB Encrypt: Failed to decrypt attributes for model ' . get_class($this) . ' (ID: ' . ($this->getKey() ?? 'n/a') . '): ' . $e->getMessage());
112+
113+
// Optionally, throw a custom exception for the application layer
114+
throw new \RuntimeException('Failed to decrypt encrypted attributes for this model. Please check the logs for details.', 0, $e);
106115
}
107116

108117
$this->_encryptedAttributesBuffer = [];

0 commit comments

Comments
 (0)