'Handling error RXJava with Throwable object

I want to do an http call like this

Observable<CimaDeviceStatus> status = CimaComm.getInstance().getService().getDeviceStatus();
status.subscribeOn(Schedulers.io()).map(result -> result).subscribe(this::onPaymentStatusUpdate, error -> handleCimaError(error));

the code works if the server answer 200, and i am able to read the body of the response

private void onPaymentStatusUpdate(CimaDeviceStatus cimaDeviceStatus) {
    ...
}

but when an error occured, handleCimaError is called, but i can't manage to read the body of the error since the argument is a Throwable, and not the object the server send

private void handleCimaError(Throwable throwable) {
    ...
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source