Spring MVC controller
Is there a nice way to avoid this repetition/boilerplate?


Yes, there is a cleaner way.

Since you are using Spring, please check the annotation @ControllerAdvice and the class ResponseEntityExceptionHandler.

To handle exceptions, you'll need to extend ResponseEntityExceptionHandler and manage the returned ResponseEntity in a method annotated with @ExceptionHandler, for example:

@ControllerAdvice(basePackageClasses = MyControllerClass.class)
public class ErrorResponseHandler extends ResponseEntityExceptionHandler {

  @ExceptionHandler(MyExceptionType.class)
  @ResponseBody
  ResponseEntity&lt;Object&gt; handleControllerException(HttpServletRequest request, Throwable ex) {
    // process the exception and wrap the response to return in ResponseEntity
  }

}


Using this approach, you service methods will remain one-liners, returning non-wrapped ArrowsGraph instances.