cloud-sdk-java icon indicating copy to clipboard operation
cloud-sdk-java copied to clipboard

ODataHealthyResponseValidator Loses Failed Batch Request

Open SpaceCondor opened this issue 1 year ago • 1 comments

In the ODataHealthyResponseValidator class there is this bit under requireHealthyResponse:

https://github.com/SAP/cloud-sdk-java/blob/845ff8349c9a85afad0986f860d3ef6956459f74/datamodel/odata-client/src/main/java/com/sap/cloud/sdk/datamodel/odata/client/request/ODataHealthyResponseValidator.java#L59C1-L72C33

        final ODataResponseException preparedException =
            new ODataResponseException(
                batchFailedRequest == null ? request : batchFailedRequest,
                httpResponse,
                msg,
                null);

        final Try<ODataServiceError> odataError = Try.of(() -> loadErrorFromResponse(result));
        if( odataError.isSuccess() ) {
            final String msgError = msg + " The OData service responded with an error message.";
            throw new ODataServiceErrorException(request, httpResponse, msgError, null, odataError.get());
        }

        throw preparedException;

The issue is that if odataError.isSuccess() is successful, the preparedException is lost, along with the failed batch request.

Should preparedException be sent as the cause to ODataServiceErrorException? The constructor parameter is currently null:

throw new ODataServiceErrorException(request, httpResponse, msgError, preparedException , odataError.get());

SpaceCondor avatar Aug 15 '24 13:08 SpaceCondor

From a first look: Agreed, if possible we should also for batch return ODataServiceErrorException with the correct request object. I raised a PR #543 to see if we can improve this 👍🏼

MatKuhr avatar Aug 15 '24 16:08 MatKuhr

Forgot to update here: This fix has also been shipped with 5.12.0, thus closing the issue. As usual, ping us if it doesn't work 😉

MatKuhr avatar Sep 09 '24 11:09 MatKuhr