start normalizing error handling in watch.

This commit is contained in:
Brendan Burns 2015-03-17 21:04:55 -07:00
parent 4725ecac3f
commit 6d763dce2b

View File

@ -17,6 +17,7 @@ limitations under the License.
package apiserver
import (
"fmt"
"net/http"
"path"
"regexp"
@ -69,15 +70,15 @@ func (h *WatchHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
defer monitor("watch", &verb, &apiResource, &httpCode, reqStart)
if req.Method != "GET" {
notFound(w, req)
httpCode = http.StatusNotFound
httpCode = errorJSON(errors.NewBadRequest(
fmt.Sprintf("unsupported method for watch: %s", req.Method)), h.codec, w)
return
}
requestInfo, err := h.info.GetAPIRequestInfo(req)
if err != nil {
notFound(w, req)
httpCode = http.StatusNotFound
httpCode = errorJSON(errors.NewBadRequest(
fmt.Sprintf("failed to find api request info: %s", err.Error())), h.codec, w)
return
}
verb = requestInfo.Verb
@ -85,8 +86,7 @@ func (h *WatchHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
storage := h.storage[requestInfo.Resource]
if storage == nil {
notFound(w, req)
httpCode = http.StatusNotFound
httpCode = errorJSON(errors.NewNotFound(requestInfo.Resource, "Resource"), h.codec, w)
return
}
apiResource = requestInfo.Resource