I've my Spring MVC controller defined in the following manner right now without much error handling mechanism :
I decided to add some error handling like the following :
Could anyone suggest if this is a correct way to handle the error OR should include the try-catch block in the code above? Also, if there's an database or any other hibernate error, I think, it would make sense to display on this line
How can I do that?
For reference (if needed), I have my other classes defined in the thread that I created for this question :
I think it's bad design to use 200 responses for error responses. If something goes wrong, the status code should reflect this: 400 if there is something wrong with the request, 500 if something goes wrong while saving. You can use exceptions and an @ExceptionHandler for this; see https://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc for more information.