50 lines
940 B
Python
50 lines
940 B
Python
from click.exceptions import BadParameter
|
|
|
|
class SessionError(Exception):
|
|
pass
|
|
|
|
|
|
class ExposedError(Exception):
|
|
pass
|
|
|
|
|
|
class ValidationError(ExposedError):
|
|
|
|
def __init__(self, msg, field=None):
|
|
|
|
super(ExposedError, self).__init__(msg)
|
|
|
|
if not field is None:
|
|
self.field = field
|
|
self.field.errors.append(self)
|
|
|
|
|
|
class CompoundError(ValidationError):
|
|
|
|
errors = None
|
|
|
|
def __init__(self, errors=None):
|
|
|
|
if not errors is None:
|
|
self.errors = errors
|
|
else:
|
|
self.errors = []
|
|
|
|
@property
|
|
def message(self):
|
|
msg = f"There were {len(self.errors)} errors."
|
|
|
|
for error in self.errors:
|
|
msg += "\n"+str(error)
|
|
|
|
return msg
|
|
|
|
def append(self, value):
|
|
self.errors.append(value)
|
|
|
|
def __len__(self):
|
|
return self.errors.__len__()
|
|
|
|
def __iter__(self):
|
|
return self.errors.__iter__()
|