Fix bug when InvalidDocumentTypeException was thrown, but unitofwork was messed with.