Mercurial > odfcast
changeset 94:2ef34abbad8d 1.5
Use http error code 422 in CheckView when a merge is not possible.
Previously the response used the code 500 in this case. This is not
useful because it's not an internal server error when the check whether
a PDF file can be merged fails because that's the point of the
CheckView. The code used now means "Unprocessable Entity" and fits
better.
Part of mpuls/issue6009
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Fri, 28 Apr 2017 20:56:22 +0200 |
parents | 48dabf4bf680 |
children | 4c1a748091d7 |
files | odfcast/convert.py |
diffstat | 1 files changed, 10 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/odfcast/convert.py Fri Apr 28 19:06:14 2017 +0200 +++ b/odfcast/convert.py Fri Apr 28 20:56:22 2017 +0200 @@ -246,6 +246,14 @@ return render_template("check.html") def post(self): + """Check that the attached PDF file is ready for merging. + If it is not ready a MergeErrorResponse is returned with + http_error_code=422. The default error code of 500 is not really + sensible because it is not an internal server error if the + attachment cannot be merged. The code 422 is used in WEB-DAV + with the meaning "Unprocessable Entity" which fits relatively + well. + """ log.debug("Checking a PDF document's readiness for merging") ffile = request.files['file'] @@ -261,13 +269,13 @@ merger.append(ffile, import_bookmarks=False) except Exception, e: log.exception("Error testing merger.append of %s" % ffile) - return MergeErrorResponse(details=str(e)) + return MergeErrorResponse(details=str(e), http_error_code=422) try: merger.write(outfile) except Exception, e: log.exception("Error testing merger.write of merged %s" % ffile) - return MergeErrorResponse(details=str(e)) + return MergeErrorResponse(details=str(e), http_error_code=422) merger.close()