client.Do错误获取状态码[关闭]

When I call client.Do method, how would I be notified for errors like 429 response code (aka too many requests). Should I expect to get a response object back with a status code 429 or will I get an error with just the message “too many requests”?

I am seeing the latter and what I need is to be able to get status code for all errors (server/dial/tcp/dns/etc.) and successes and only in some cases I can get the actual code in case of errors. Is there anyway to get all response codes irrespective of the error type - the error message seems to reflect the details but would still like to get the code if possible.

The http documentation covers this very clearly.

Of particular interest are the documentation for Do:

An error is returned if caused by client policy (such as CheckRedirect), or failure to speak HTTP (such as a network connectivity problem). A non-2xx status code doesn't cause an error.

(Emphasis added)

And the documentation for the Response object returned by Do:

type Response struct {
    Status     string // e.g. "200 OK"
    StatusCode int    // e.g. 200