You don't need to do this because, below is a snippet of how to make the webapp in openmrs display an error message in a standard way, you will need to add the HttpServletRequest object parameter to the method signature of the controller: and specify your error message code that has been translated in the message.properties file

request.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "my.errorMessageCode", WebRequest.SCOPE_SESSION);