golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.75k stars 17.63k forks source link

x/net/websocket: ErrBadStatus should include the bad status code #13528

Open noahlt opened 8 years ago

noahlt commented 8 years ago

Right now, if a x/net/websocket client connects to an HTTP endpoint and receives a response with any status other than 101, it returns an ErrBadStatus (source). This error does not include the actual status code received, and so users of this library are unable to distinguish between, for instance, 403 Forbidden and 500 Internal Server Error responses.

One solution would be to add a websocket.HTTPStatusError which implements websocket.ProtocolError and also includes an exported Status field. This way, users could (if they wished) check the type of the error and switch on the Status field to determine correct behavior.

crewjam commented 4 years ago

I have a use case where it would be handy to have the entire http response. Perhaps something along the lines of x/oauth2.RetrieveError ?