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