I am creating a web application using Spring Boot. In my controller, there can be situations when some errors occur. I need to notify my end users about these errors.
For example there might be an error while saving the data in the database. In this case I need to display a custom error message.
Also sometimes an exception might be thrown, a proper user friendly error message needs to be reported.
I read about using ExceptionHandler to do this. The problem is with this approach, I need to create different views (html files since I am using Thymeleaf) with the error message. So for each exception/error condition, I will need to create a separate HTML file with the hardcoded error message.
Is there anyway whereby a single error.html page can be used and the error message in that page customized depending on the exact error that has occured in the controller?