Better error checking for document post
Merge branch 'api' into devel