Make quota exceeded failures 400 errors in REST#145
Conversation
c7958dc to
3999094
Compare
| serializer.save(creator=user) | ||
| except QuotaLimitedError: | ||
| raise serializers.ValidationError( | ||
| {'size': ['This file would exceed the size quota for this folder.']} |
There was a problem hiding this comment.
If there's an easier way to achieve this response structure, let me know. I want it to mirror the structure of the other types of validation failure responses.
There was a problem hiding this comment.
If the error occurs within a serializer field validator, the field will be automatically set. Since this is not thrown during validation, unfortunately it won't be auto-set here.
An alternative implementation could implement an internal API to determine whether a given allocation would exceed the quota. We'd then have to either do the entire API operation atomically, or we'd have to re-check the same thing on save anyway.
Since end users ultimately get the right response this way, and it seems simpler to implement (though slightly less "correct", since we want to try to do all validation in the serializer), I think the current way is best.
There was a problem hiding this comment.
Actually, I'll weaken my position: I think the current way is adequate. The alternative would require a new File/Folder/Quota API, but probably won't be any more complex on the DRF layer, since we'd no longer catch exceptions during .save.
d525294 to
0471975
Compare
Fixes #144