# XXX TODO
BackendMixin = BaseHandler
+class APIError(Exception):
+ """
+ Raised if there has been an error in the API
+ """
+ def __init__(self, code, message):
+ super().__init__()
+
+ self.code = code
+ self.message = message
+
+ def __str__(self):
+ return self.message
+
+
class APIMixin(KerberosAuthMixin, BackendMixin):
# Generally do not permit users to authenticate against the API
allow_users = False
"mem_level" : 9,
}
- def write_error(self, code, **kwargs):
- # Send a JSON-encoded error message
+ def write_error(self, code, exc_info):
+ """
+ Sends a JSON-encoded error message
+ """
+ type, error, traceback = exc_info
+
+ # We only handle API errors here
+ if not isinstance(error, APIError):
+ return super().write_error(code, exc_info)
+
+ # We send errors as 200
+ self.set_status(200, reason=error.message)
+
self.finish({
- "error" : True,
- # XXX add error string
+ "error" : {
+ "code" : error.code,
+ "message" : error.message,
+ },
})
def _decode_json_message(self, message):
)
except uploads.UnsupportedDigestException as e:
- raise tornado.web.HTTPError(400,
- "Unsupported digest %s" % digest_algo) from e
+ raise base.APIError(400, "Unsupported digest %s" % digest_algo) from e
except users.QuotaExceededError as e:
- raise tornado.web.HTTPError(400,
- "Quota exceeded for %s" % self.current_user) from e
+ raise base.APIError(400, "Quota exceeded for %s" % self.current_user) from e
except ValueError as e:
- raise tornado.web.HTTPError(400, "%s" % e) from e
+ raise base.APIError(400, "%s" % e) from e
# Send the ID of the upload back to the client
self.finish({
await upload.copyfrom(self.buffer)
except ValueError as e:
- raise tornado.web.HTTPError(400, "%s" % e) from e
+ raise base.APIError(400, "%s" % e) from e
@base.negotiate
async def delete(self, uuid):