]> git.ipfire.org Git - pbs.git/commitdiff
uploads: Use errno codes
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 20 Oct 2023 09:33:56 +0000 (09:33 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 20 Oct 2023 09:33:56 +0000 (09:33 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/web/uploads.py

index 76c09d3c21c736fca429ea27d3ff924e96c52321..8df919f3bd5a1c5267f3e7f910ede2553ccff7de 100644 (file)
@@ -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({})