I have a Carrierwave uploader that accepts multiple files and usage is set up in the typical way in the models.
mount_uploaders :attached_files, AttachedFileUploader
I’d like to make use of the content_type_allowlist functionality so I’ve overriden that in the uploader class.
def content_type_allowlist
[
'image/jpeg',
'image/gif',
'image/png', . . .
This works. When a file with a content type on the list is uploaded, a CarrierWave::IntegrityError is thrown, which looks like it occurs in the cache function.
Where is the optimal way of catching this exception so I can return a message to the view. Out of the box I’m getting a 500 but I’d like to recover and return to the form. Are folks typically doing this inside the create and update methods in the controllers?
Ideally I’d like to do such a thing in a validator I have for other uploader rules
class AttachedFilesValidator < ActiveModel::Validator
But it seems like the exception occurs before that validation gets hit.
It looks like all you have to do is tell the "uploader" to validate the integrity and this will be added as an error on the model, rather than raising an Error
That being said it seems like something else is going on here because that option is turned on by default:
Default Configuration Options Here
Uploader Options: Source
Currently your Error comes from Here
Validations to handle Errors can be found Here