ardielle / ardielle-tools

Apache License 2.0
18 stars 19 forks source link

generated go client does not return http request status if response is not Json #105

Closed havetisyan closed 5 years ago

havetisyan commented 5 years ago

As part of this commit: #96 (https://github.com/ardielle/ardielle-tools/commit/e2ddb49f638c3c53ac7cfabbe5fcff0363253ecb#diff-b6ebcf939863983eb4d9dfc8f325ee64) the go client generation replaced:

json.Unmarshal(contentBytes, &errobj)
if errobj.Code == 0 {
    errobj.Code = resp.StatusCode
}

with the following code:

err = json.Unmarshal(contentBytes, &errobj)
if err != nil {
    return nil, "", err
}
if errobj.Code == 0 {
    errobj.Code = resp.StatusCode
}

So if the server returns unexpected code such as 500, 503, etc, without any json object then the client fails to Unmarshal the data since it's not json. Before we would correctly ignore the message and return the status code in the errobj but now we get an err from the Unmarshal call and return that the caller and thus the client does not know why the request was rejected.