-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to get the http response details by Dapr HttpBinding if the state code is not 200 #783
Comments
The root cause here but I am not sure how to fix it. You can check this function
In the line 320, it enqueue a ResponseFutureCallback. It converts the okhttp3 response into the response object expected internally by the SDK.
You can check the function
line 372
It converts the okhttp3.Response to DaprError, then it will throw DaprException. The DaprException is just an exception so we can not get the original reponse details. It seem that we need to add a params like
Then we may need to add other field in the DaprError and DaprException, to save some original reponse details(such as the original body). I am not sure about how to make it work for this part. If we fix this issue in this way, here is how it works in the services to use
|
@yaron2 @artursouza @skyao @CrazyHZM Could you please have a look? Please correct me if anything wrong. |
Part of the underlying issue is that the HTTP binding explicitly treats non-200 status codes in the response as an error and returns an error object. This translates to the response data being lost in both the HTTP API and the gRPC API because the error condition causes the API to return no data (other than the error). I opened a PR in The binding could also be changed to support setting this flag on the binding component itself but it seems like this behavior may be accidentally depended on and so changing it at the binding level might cause unintended errors whereas this allows per-invocation granularity. This would allow you to prevent an exception from being raised by doing something like: 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);
// Add new metadata flag here
metadata.put("treatNon200AsError", "false");
return client.invokeBinding(properties.getHttpBindingName(), DaprBindingOperation.POST.getValue(), null, metadata, BBBResponse.class);
} |
Thank @johnewart. According to the latest code and test(https://github.com/dapr/components-contrib/blob/master/bindings/http/http_test.go), the metadata name should be "errorIfNot2XX" but not "treatNon200AsError".
I will try to use this flag as a work around. Excepting a better solution in SDK v1.8. |
Here is another idea to get the original response refer to the WebClientResponseException(org.springframework.web.reactive.function.client) There are some API to get more details when you meet error. |
Hi, @johnewart Thank you for your sharing, but I still get an exception using the "errorIfNot2XX" metedata. Here is my impl:
And the
|
We will try. We need volunteers in the Java SDK. |
@artursouza assign me please. |
@artursouza @MatejNedic @maciek047 is there any updated? |
This PR should allow the raw payload to be parsed by the application's code: #1009 |
Reopening as the other PR did not fix this issue. |
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.
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:
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:
The text was updated successfully, but these errors were encountered: