Search code examples
javaspringhystrixfallback

Spring MVC ResponseEntity Hystrix fallback


I Have a service method that returns a ResponseEntity<List<Attachment>> and its hystrix fallback method must also return a ResponseEntity<List<Attachment>>.
The problem is that I need to return a String message that clarifies the error to the user instead of returning a new Arraylist<>()

- Here is my method

@Override
@HystrixCommand(fallbackMethod = "getAttachmentsFallback")
public ResponseEntity<List<AttachmentDto>> getAttachments(IAttachable entity) {
    List<AttachmentDto> attachments = client.getAttachments(entity.getAttachableId(), entity.getClassName(),
            entity.getAppName());
    return new ResponseEntity<List<AttachmentDto>>(attachments, HttpStatus.OK);
}

And that's its fallback

public ResponseEntity<List<AttachmentDto>> getAttachmentsFallback(IAttachable entity, Throwable e) {
    //I need to return a String instead of the new Arraylist<AttachmentDto>() 
    return new ResponseEntity<List<AttachmentDto>>(new ArrayList<AttachmentDto>(), HttpStatus.INTERNAL_SERVER_ERROR);
}

Solution

  • I Made it work by doing ResponseEntity with no args instead of ResponseEntity<List<AttachmentDto>>

    Thanks guys