from . import flavors
[docs]
class InvalidUsage(Exception):
status_code = 400
def __init__(self, message, status_code=None, payload=None):
super().__init__()
self.message = message
if status_code is not None:
self.status_code = status_code
self.payload = payload
[docs]
def to_dict(self):
rv = dict(self.payload or ())
rv["message"] = self.message
return rv
[docs]
class UnknownFlavor(Exception):
def __init__(self, *args, **kwargs):
message = (
"Allowed flavors are "
+ ", ".join([f"'{flavor}'" for flavor in flavors.allowed_flavors()])
+ "."
)
super().__init__(message, *args, **kwargs)
[docs]
class FlavorNotSet(InvalidUsage):
def __init__(self, *args, **kwargs):
super().__init__(message="No flavor has been set.", *args, **kwargs)