forked from mystiq/dex
storage/kubernetes: don't automatically print errors on bad HTTP status codes
These status codes spam the error logs for events like key rotation and third party resource creation. In these cases "bad" status codes are expected and shouldn't be automatically printed.
This commit is contained in:
parent
ba9f6c6cd6
commit
138ff96c00
1 changed files with 6 additions and 8 deletions
|
@ -10,7 +10,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -95,18 +94,17 @@ func checkHTTPErr(r *http.Response, validStatusCodes ...int) error {
|
||||||
return fmt.Errorf("read response body: %v", err)
|
return fmt.Errorf("read response body: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check this case after we read the body so the connection can be reused.
|
||||||
|
if r.StatusCode == http.StatusNotFound {
|
||||||
|
return storage.ErrNotFound
|
||||||
|
}
|
||||||
|
|
||||||
var url, method string
|
var url, method string
|
||||||
if r.Request != nil {
|
if r.Request != nil {
|
||||||
method = r.Request.Method
|
method = r.Request.Method
|
||||||
url = r.Request.URL.String()
|
url = r.Request.URL.String()
|
||||||
}
|
}
|
||||||
err = &httpErr{method, url, r.StatusCode, body}
|
return &httpErr{method, url, r.StatusCode, body}
|
||||||
log.Printf("%s", err)
|
|
||||||
|
|
||||||
if r.StatusCode == http.StatusNotFound {
|
|
||||||
return storage.ErrNotFound
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the response body. The initial request is drained so the connection can
|
// Close the response body. The initial request is drained so the connection can
|
||||||
|
|
Loading…
Reference in a new issue