Closed MickeyShnaiderman-RecoLabs closed 4 months ago
I will close this one since we are planning to deprecate v2. I will update it for v4
@duytiennguyen-okta 's going to update the equivalent code in the current version of the sdk client that is generated from this template:
We think the improvement should be to let the caller have access to both the error and the response objects and be responsible to themselves for checking on nils
func buildResponse(resp *http.Response, cli *APIClient, v interface{}) (*APIResponse, error) {
//...
/*
if err == io.EOF {
err = nil
}
if err != nil {
return nil, err
}
return response, nil
*/
return response, err
}
The decoder might fail on the given
v
object, but the returned Golang error is not indicative enough. Return the response to let the user inspect it to make things easier.Summary
The SDK functions might fail upon a malformed JSON returned from the server. The internal
buildResponse
function tries to unmarshal the response. If it fails, it returns the native Golang error without the response from the server. The native error is not informative, so the response is crucial to determine the root cause, especially in a production environment where debugging is not possible. To solve that, thebuildResponse
function returns the response from the server (instead ofnil
) even when there is an error. This should not break any existing functionality and usage of the SDK.Type of PR
Test Information
Go Version: 1.22.0 Os Version: macOS Sonoma 14.2.1 OpenAPI Spec Version:
Signoff
make fmt
on my code