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

Unable to get the http response details by Dapr HttpBinding if the state code is not 200

Open ParrySMS opened this issue 3 years ago • 0 comments

Expected Behavior

I have service A, and service A will call service B by the DaprClient. All thing works when service B returns the response with state code 200.

    @Autowired
    private DaprClient client;
   
    @Override
    public Mono<BBBResponse> getUserData(String realms, String accessToken) {
        var metadata = setUpHeaderParams(accessToken);
        var queryParams = setUpQueryParams("m_getUserData");
        var path = toQueryParamsPath(String.format(AUTHENTICATE_PATH, realms), queryParams);
        metadata.put("path", path);
        return client.invokeBinding(properties.getHttpBindingName(), DaprBindingOperation.POST.getValue(), null, metadata, BBBResponse.class);
    }

If the state code is not 200, I want to get the original response details. The service B will return a response with a 401 state code like this one:

{
    "code": "BS_0002"
    "message": "The access token is expired."
}

Actual Behavior

I will get an error like this one if I get the 401 from Service B.

"error when invoke output binding aaa-service-http-binding: received status code 401."

There should be a way to catch this HTTP binding exception or somehow get the original response. I need to get the original response to do something.

Steps to Reproduce the Problem

Use a DaprClient to call other APIs by function invokeBinding().

Get a response but the state code is not 200.

No way to get the orginal response but a dapr error like "error when invoke output binding XXXX : received status code YYY."

Release Note

RELEASE NOTE:

ParrySMS avatar Sep 19 '22 08:09 ParrySMS