Refactored InvalidError handling into a serializer concern.