error.go 384 B

1234567891011121314151617181920212223242526272829
  1. package s3util
  2. import (
  3. "bytes"
  4. "fmt"
  5. "io"
  6. "net/http"
  7. )
  8. type respError struct {
  9. r *http.Response
  10. b bytes.Buffer
  11. }
  12. func newRespError(r *http.Response) *respError {
  13. e := new(respError)
  14. e.r = r
  15. io.Copy(&e.b, r.Body)
  16. r.Body.Close()
  17. return e
  18. }
  19. func (e *respError) Error() string {
  20. return fmt.Sprintf(
  21. "unwanted http status %d: %q",
  22. e.r.StatusCode,
  23. e.b.String(),
  24. )
  25. }