def __init__(self, response): # Collect validation errors as list of strings. self.validation_errors = {} # Loop errors. for error in response.json()["errors"]: # Handle only validation errors. if error["status"] == 422: field = "generic" if "field" in error["variables"]: field = error["variables"]["field"] or error["detail"] if field not in self.validation_errors: self.validation_errors[field] = [] self.validation_errors[field].append(error["detail"]) if self.validation_errors.__len__() == 1: validation_error = "There is {} validation error." else: validation_error = "There are {} validation errors." HTTPError.__init__( self, validation_error.format(self.validation_errors.__len__()), response=response, )
def __init__(self, error_details): """Error object instantiation.""" self.api_method = error_details["api_method"] self.url = error_details["url"] self.verb = error_details["verb"] self.status_code = error_details["status_code"] self.message = error_details["message"] self.print_message = ("\nArtifactory REST API operation : " + self.api_method + "\nURL : " + self.url + "\nVerb : " + self.verb + "\nStatus Code : " + str(self.status_code) + "\nMessage : " + self.message) HTTPError.__init__(self, self.print_message)