"""Application and custom Exceptions.""" from oto import response from oto.adaptors.flask import flaskify from backend.constants import error as error_const class RequestError(Exception): """Request Error Exception class.""" def __init__(self, message, error_code=error_const.BAD_REQUEST_CODE, http_status=400): """Constructor. Args: message (str/dict): Response message status_code (int): HTTP status code """ super().__init__() self.message = message self.error_code = error_code self.http_status = http_status def __str__(self): """Convert message to string.""" return str(self.message) def __eq__(self, other): """Compare two RequestError objects.""" return ( self.message == other.message and self.error_code == other.error_code and self.http_status == other.http_status ) def make_flask_response(self): """Make Flask Response.""" return flaskify(response.create_error_response( self.error_code, self.message, status=self.http_status)) class ValidationError(RequestError): """Validation Error Exception class.""" def __init__(self, message): """Constructor. Args: message (str/dict): Response message """ super().__init__(message, error_code=error_const.VALIDATION_ERROR_CODE) class IntegrityError(Exception): """IntegrityError Exception.""" pass