ocket8888 commented on a change in pull request #5003:
URL: https://github.com/apache/trafficcontrol/pull/5003#discussion_r485098558



##########
File path: traffic_ops/v3-client/server.go
##########
@@ -117,6 +117,9 @@ func (to *Session) CreateServer(server tc.ServerNullable) 
(tc.Alerts, ReqInf, er
        resp, remoteAddr, err := to.request(http.MethodPost, API_SERVERS, 
reqBody, nil)
        reqInf.RemoteAddr = remoteAddr
        if err != nil {
+               if strings.Contains(err.Error(), "400 Bad Request[400]") {
+                       reqInf.StatusCode = resp.StatusCode
+               }

Review comment:
       I think you misunderstood what I was saying here. Instead of checking 
the error at all, before you even check if it's `nil` you can just do 
`reqInf.StatusCode = resp.StatusCode`. That way the status code is reported 
faithfully no matter what it is. Like:
   ```go
   //...
   resp, remoteAddr, err := to.request(http.MethodPost, API_SERVERS, reqBody, 
nil)
   reqInf.RemoteAddr = remoteAddr
   reqInf.StatusCode = resp.StatusCode
   if err != nil {
        return alerts, reqInf, err
   }
   defer resp.Body.Close()
   //...
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to