def wrap_exception(exception, cause):
        """
        Wraps another exception into specified application exception object.

        If original exception is of ApplicationException type it is returned without changes.
        Otherwise the original error is set as a cause to specified ApplicationException object.

        :param exception: an ApplicationException object to wrap the cause

        :param cause: an original error object

        :return: an original or newly created ApplicationException
        """
        if isinstance(cause, ApplicationException):
            return cause
        
        exception.with_cause(cause)
        return exception
Wraps another exception into specified application exception object.

        If original exception is of ApplicationException type it is returned without changes.
        Otherwise the original error is set as a cause to specified ApplicationException object.

        :param exception: an ApplicationException object to wrap the cause

        :param cause: an original error object

        :return: an original or newly created ApplicationException