diff --git a/src/python/WMCore/Database/CMSCouch.py b/src/python/WMCore/Database/CMSCouch.py index 54add0f501..75f9e5dd8f 100644 --- a/src/python/WMCore/Database/CMSCouch.py +++ b/src/python/WMCore/Database/CMSCouch.py @@ -148,31 +148,31 @@ def checkForCouchError(self, status, reason, data=None, result=None): Check the HTTP status and raise an appropriate exception. """ if status == 400: - raise CouchBadRequestError(reason, data, result) + raise CouchBadRequestError(reason, data, result, status) elif status == 401: - raise CouchUnauthorisedError(reason, data, result) + raise CouchUnauthorisedError(reason, data, result, status) elif status == 403: - raise CouchForbidden(reason, data, result) + raise CouchForbidden(reason, data, result, status) elif status == 404: - raise CouchNotFoundError(reason, data, result) + raise CouchNotFoundError(reason, data, result, status) elif status == 405: - raise CouchNotAllowedError(reason, data, result) + raise CouchNotAllowedError(reason, data, result, status) elif status == 406: - raise CouchNotAcceptableError(reason, data, result) + raise CouchNotAcceptableError(reason, data, result, status) elif status == 409: - raise CouchConflictError(reason, data, result) + raise CouchConflictError(reason, data, result, status) elif status == 410: - raise CouchFeatureGone(reason, data, result) + raise CouchFeatureGone(reason, data, result, status) elif status == 412: - raise CouchPreconditionFailedError(reason, data, result) + raise CouchPreconditionFailedError(reason, data, result, status) elif status == 413: - raise CouchRequestTooLargeError(reason, data, result) + raise CouchRequestTooLargeError(reason, data, result, status) elif status == 416: - raise CouchRequestedRangeNotSatisfiableError(reason, data, result) + raise CouchRequestedRangeNotSatisfiableError(reason, data, result, status) elif status == 417: - raise CouchExpectationFailedError(reason, data, result) + raise CouchExpectationFailedError(reason, data, result, status) elif status == 500: - raise CouchInternalServerError(reason, data, result) + raise CouchInternalServerError(reason, data, result, status) elif status in [502, 503, 504]: # There are HTTP errors that CouchDB doesn't raise but can appear # in our environment, e.g. behind a proxy. Reraise the HTTPException @@ -1121,92 +1121,90 @@ def __init__(self, reason, data, result, status=None): self.status = status def __str__(self): - "Stringify the error" - if self.status != None: - errorMsg = "NEW ERROR STATUS! UPDATE CMSCOUCH.PY!: %s\n" % self.status - else: - errorMsg = "" - return errorMsg + "%s - reason: %s, data: %s result: %s" % (self.type, - self.reason, - repr(self.data), - self.result) + """Stringify the error""" + errorMsg = "" + if self.type == "CouchError": + errorMsg += f"NEW ERROR TYPE/STATUS! UPDATE CMSCOUCH.PY!: Status: {self.status}\n" + errorMsg += f"Error type: {self.type}, Status code: {self.status}, " + errorMsg += f"Reason: {self.reason}, Data: {repr(self.data)}" + return errorMsg class CouchBadRequestError(CouchError): - def __init__(self, reason, data, result): - CouchError.__init__(self, reason, data, result) + def __init__(self, reason, data, result, status): + CouchError.__init__(self, reason, data, result, status) self.type = "CouchBadRequestError" class CouchUnauthorisedError(CouchError): - def __init__(self, reason, data, result): - CouchError.__init__(self, reason, data, result) + def __init__(self, reason, data, result, status): + CouchError.__init__(self, reason, data, result, status) self.type = "CouchUnauthorisedError" class CouchNotFoundError(CouchError): - def __init__(self, reason, data, result): - CouchError.__init__(self, reason, data, result) + def __init__(self, reason, data, result, status): + CouchError.__init__(self, reason, data, result, status) self.type = "CouchNotFoundError" class CouchNotAllowedError(CouchError): - def __init__(self, reason, data, result): - CouchError.__init__(self, reason, data, result) + def __init__(self, reason, data, result, status): + CouchError.__init__(self, reason, data, result, status) self.type = "CouchNotAllowedError" class CouchNotAcceptableError(CouchError): - def __init__(self, reason, data, result): - CouchError.__init__(self, reason, data, result) + def __init__(self, reason, data, result, status): + CouchError.__init__(self, reason, data, result, status) self.type = "CouchNotAcceptableError" class CouchConflictError(CouchError): - def __init__(self, reason, data, result): - CouchError.__init__(self, reason, data, result) + def __init__(self, reason, data, result, status): + CouchError.__init__(self, reason, data, result, status) self.type = "CouchConflictError" class CouchFeatureGone(CouchError): - def __init__(self, reason, data, result): - CouchError.__init__(self, reason, data, result) + def __init__(self, reason, data, result, status): + CouchError.__init__(self, reason, data, result, status) self.type = "CouchFeatureGone" class CouchPreconditionFailedError(CouchError): - def __init__(self, reason, data, result): - CouchError.__init__(self, reason, data, result) + def __init__(self, reason, data, result, status): + CouchError.__init__(self, reason, data, result, status) self.type = "CouchPreconditionFailedError" class CouchRequestTooLargeError(CouchError): - def __init__(self, reason, data, result): + def __init__(self, reason, data, result, status): # calculate the size of this JSON serialized object docSize = sys.getsizeof(json.dumps(data)) - errorMsg = f"Document is too large {docSize} bytes and is not accepted by CouchDB." - CouchError.__init__(self, reason, errorMsg, result) + errorMsg = f"Document has {docSize} bytes and it's too large to be accepted by CouchDB." + CouchError.__init__(self, reason, errorMsg, result, status) self.type = "CouchRequestTooLargeError" class CouchExpectationFailedError(CouchError): - def __init__(self, reason, data, result): - CouchError.__init__(self, reason, data, result) + def __init__(self, reason, data, result, status): + CouchError.__init__(self, reason, data, result, status) self.type = "CouchExpectationFailedError" class CouchRequestedRangeNotSatisfiableError(CouchError): - def __init__(self, reason, data, result): - CouchError.__init__(self, reason, data, result) + def __init__(self, reason, data, result, status): + CouchError.__init__(self, reason, data, result, status) self.type = "CouchRequestedRangeNotSatisfiableError" class CouchInternalServerError(CouchError): - def __init__(self, reason, data, result): - CouchError.__init__(self, reason, data, result) + def __init__(self, reason, data, result, status): + CouchError.__init__(self, reason, data, result, status) self.type = "CouchInternalServerError" class CouchForbidden(CouchError): - def __init__(self, reason, data, result): - CouchError.__init__(self, reason, data, result) + def __init__(self, reason, data, result, status): + CouchError.__init__(self, reason, data, result, status) self.type = "CouchForbidden"