Catch CipherError and TypeError in run_cipher and raise EncryptorError #4365
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Wraps OpenSSL::Cipher::CipherError and TypeError in a custom EncryptorError to allow centralized handling in ApplicationController. This enables consistent 500 error responses with clearer messages like "Error while processing encrypted data".
A short explanation of the proposed change:
This change wraps OpenSSL::Cipher::CipherError and TypeError raised during encryption/decryption in a custom EncryptorError exception. The ApplicationController is updated to catch this new exception.
An explanation of the use cases your change solves
If a TypeError is raised by OpenSSL::PKCS5.pbkdf2_hmac (e.g., due to a nil or invalid key), or if a CipherError occurs during encryption or decryption, these are now caught and wrapped in a custom EncryptorError. This ensures the error is handled gracefully in the ApplicationController, and the user receives a standardized and meaningful 500 error response.
Links to any other associated PRs
Improves Add error handling for invalid encryption keys with logging #4326
I have reviewed the contributing guide
I have viewed, signed, and submitted the Contributor License Agreement
I have made this pull request to the
mainbranchI have run all the unit tests using
bundle exec rakeI have run CF Acceptance Tests