Error handling while uploading a document

Refer to Issues: #1395 and #1396