from tracker.json_utils import JsonException class JsonApiError(JsonException): message = 'An error occured' status = 500 info = "There was an error with that request" data = {} def __init__(self, info=None): super().__init__("") if info: self.info = info def __json__(self): return { "status": self.status, "info": self.info, "code": self.__class__.__name__, "data": self.data, } class UnauthenticatedError(JsonApiError): status = 401 info = "Please login" class SessionExpiredError(JsonApiError): status = 401 info = "Please login again" class IncorrectLoginError(JsonApiError): def __init__(self, username=None, message=None): super().__init__(message) self.username = username status = 403 info = "Failed to login" class NonAuthorisedApolloAccount(IncorrectLoginError): info = ( "Unable to login with those credentials. If you attempted to login " "with an Apollo Account, that account does not seem to be configured for " "accessing The Whitelist. Please email ops@whtlst.in with the account you " "want to connect for assistance." ) class NotFoundError(JsonApiError): status = 404 info = "Unknown resource" class BadRequestError(JsonApiError): status = 400 info = "The request had malformed or missing data" def __init__(self, info=None, **bad_data_information): self.info = info or "The request had malformed or missing data" self.message = self.info self.data = { 'bad_data': bad_data_information } # errors = { # cls.__class__.__name__: {'info': cls.info, 'status': cls.status} # for cls in [UnauthenticatedError] # }