Package church.i18n.processing.exception
Interface MandatoryExceptionTranslator<T extends Exception>
- Type Parameters:
T- Type of exception it handles. E.g. SqlException
public interface MandatoryExceptionTranslator<T extends Exception>
Common interface for writing mappers of (framework) exceptions. Many times we encounter common
framework messages that needs to be parsed to extract information from them. Frameworks are used
repeatedly in multiple projects and handling those exceptions is most of the time the same. This
interface should unify handling of such cases and reuse once written implementation. Example of
such implementation could be SqlException of particular database driver or common network-related
exceptions.
-
Method Summary
Modifier and TypeMethodDescription@NotNull ProcessingExceptiondefaultException(T exception) The default exception to return when translator is not capable to handle provided exception.@NotNull ProcessingExceptionParse framework or other repeated exception into aProcessingException.default voidtranslateAndThrow(T exception) Translate the exception with the translator.
-
Method Details
-
translate
Parse framework or other repeated exception into aProcessingException. Please extract as much information as needed to properly understand error state but no more than that. Beware of security concerns and do not provide any sensitive information. Please do not return directlyThrowable.getMessage()orThrowable.getLocalizedMessage()without parsing its content and selecting only information you trust. Never trust messages from third party libraries, you do not have a control over them. One version may return correct message, later version may return sensitive information. When you implement this interface, try to write as many test cases as you can to validate particular exception mapping. When library version for which you write exception translator changes, you may need to validate that messages has not changed and mapping has still the same behaviour.- Parameters:
exception- An exception to parse.- Returns:
- Instance of
ProcessingExceptionin the case this mapper is able to properly parse it,defaultException(Exception)otherwise.
-
translateAndThrow
Translate the exception with the translator. In the case the translator is capable to handle such exception, translated exception will be thrown, otherwise no action is performed.- Parameters:
exception- Exception to translate.
-
defaultException
The default exception to return when translator is not capable to handle provided exception.- Parameters:
exception- Exception to translate.
-