Should I error-check Close() on a response body?

There are two things to consider: What would you do with it if you checked it and there was an error? And, what would the side-effects be if there was an error?

In most cases, for closing a response body, the answer to both questions is… absolutely nothing. If there’s nothing you’d do if there was an error and the error has no appreciable impact, there’s no reason to check it.

Also note that Close() returns an error in order to fulfill the io.Closer interface; the function doesn’t necessarily return an error. You’d need to check the source to know for sure if it has an error case.

Leave a Comment