I'd argue that resp, err := http.Get("http://google.com/foo/bar") not having any err's but resp.StatusCode indicating 404 is misleading.
If 404 and 500 are not errors, what are? Why are there 2 types of errors?
200-299,400-599 status codes may have headers and bodies, that's a lot to
overload on an error implementation.
On Tue, 12 Sep 2017, 21:56 Gregory Reshetniak notifications@github.com
wrote:
I'd argue that resp, err := http.Get("http://google.com/foo/bar") not
having any err's but resp.StatusCode indicating 404 is misleading.If 404 and 500 are not errors, what are? Why are there 2 types of errors?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/golang/go/issues/21846, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAAcA4qsBOWa1uDCxXKFp0BdfSOYmN66ks5shnGDgaJpZM4PUh_M
.
I'm pretty sure this is already documented. (on phone)
The documentation:
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.
If the returned error is nil, the Response will contain a non-nil Body which the user is expected to close. If the Body is not closed, the Client's underlying RoundTripper (typically Transport) may not be able to re-use a persistent TCP connection to the server for a subsequent "keep-alive" request.
Also note that, on top of what @davecheney said, making 4xx and 5xx status codes also errors would break the Go1 compatibility promise.
Is there a catchall non-error return code object to match against? I mean, having != 200,201,301,302 etc etc is a lot of boilerplate to simply make sure my request has made it.
Python's requests lib would error out on 4/5 and just run happily on everything else, I'd sort of used to such behavior.
code >= 400 is what I tend to use.
There doesn'r seem to be a bug here, so I'm closing this. If you'd like to change how net/http works, feel free to submit a proposal.
Most helpful comment
200-299,400-599 status codes may have headers and bodies, that's a lot to
overload on an error implementation.
On Tue, 12 Sep 2017, 21:56 Gregory Reshetniak notifications@github.com
wrote: