Reputation: 13986
I have a function that is both an HTTP endpoint and a function that I call elsewhere in the Java program:
@RequestMapping(method = RequestMethod.GET)
public @ResponseBody MyObject getObject(final HttpServletRequest request, final HttpServletResponse response)
The problem is in error handling. Functionality I would like on error:
Trying to figure out the best way to do it. Thought about just returning a Java.lang.Object, but that's a lot of casting and type checking.
Upvotes: 0
Views: 170
Reputation: 342
Add a Spring exception handler when calling it from web and then have the handler return your JSON.
Better approach might be to refactor the functionality into a service method then you can have the HTTP call handle the exception in it's own way and internal calls handle it however you want.
Edit
The second approach would be slightly easier to test too.
Upvotes: 1