From: Michael Tremer Date: Fri, 20 Oct 2023 09:33:56 +0000 (+0000) Subject: uploads: Use errno codes X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec036a131809f16003eabefb517ddcff6f493747;p=pbs.git uploads: Use errno codes Signed-off-by: Michael Tremer --- diff --git a/src/web/uploads.py b/src/web/uploads.py index 76c09d3c..8df919f3 100644 --- a/src/web/uploads.py +++ b/src/web/uploads.py @@ -19,6 +19,7 @@ # # ############################################################################### +import errno import io import tornado.web @@ -83,13 +84,13 @@ class APIv1IndexHandler(base.APIMixin, tornado.web.RequestHandler): ) except uploads.UnsupportedDigestException as e: - raise base.APIError(400, "Unsupported digest %s" % digest_algo) from e + raise base.APIError(errno.ENOTSUP, "Unsupported digest %s" % digest_algo) from e except users.QuotaExceededError as e: - raise base.APIError(400, "Quota exceeded for %s" % self.current_user) from e + raise base.APIError(errno.EDQUOT, "Quota exceeded for %s" % self.current_user) from e except ValueError as e: - raise base.APIError(400, "%s" % e) from e + raise base.APIError(errno.EINVAL, "%s" % e) from e # Send the ID of the upload back to the client self.finish({ @@ -127,11 +128,11 @@ class APIv1DetailHandler(base.APIMixin, tornado.web.RequestHandler): # Fetch the upload upload = self.backend.uploads.get_by_uuid(uuid) if not upload: - raise tornado.web.HTTPError(404, "Could not find upload %s" % uuid) + raise tornado.web.HTTPError(400, "Could not find upload %s" % uuid) # Fail if we did not receive anything if not self.buffer.tell(): - raise tornado.web.HTTPError(400, "No data received") + raise base.APIError(errno.ENODATA, "No data received") # Import the payload from the buffer with self.db.transaction(): @@ -139,7 +140,7 @@ class APIv1DetailHandler(base.APIMixin, tornado.web.RequestHandler): await upload.copyfrom(self.buffer) except ValueError as e: - raise base.APIError(400, "%s" % e) from e + raise base.APIError(errno.EINVAL, "%s" % e) from e # Send a positive response self.finish({})