Handle unexpected statuscodes from the log provider

**What**
- Use NotImplemented when we get a 404 from the log provider.  When we
get a 200, process the log request, as normal.  For all other status
codes, return a sever error with a message stating that the
response was unexpected.  The message will contain the original status
code to assist with debugging

Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
This commit is contained in:
Lucas Roesler 2019-06-23 20:46:34 +02:00 committed by Alex Ellis
parent 02ccccbe60
commit 74d08126b3

View File

@ -2,6 +2,7 @@ package handlers
import ( import (
"context" "context"
"fmt"
"io" "io"
"log" "log"
"net/http" "net/http"
@ -66,6 +67,11 @@ func NewLogHandlerFunc(logProvider url.URL, timeout time.Duration) http.HandlerF
} }
defer logResp.Body.Close() defer logResp.Body.Close()
switch logResp.StatusCode {
case http.StatusNotFound, http.StatusNotImplemented:
w.WriteHeader(http.StatusNotImplemented)
return
case http.StatusOK:
// watch for connection closures and stream data // watch for connection closures and stream data
// connections and contexts should have cancel methods deferred already // connections and contexts should have cancel methods deferred already
select { select {
@ -78,6 +84,9 @@ func NewLogHandlerFunc(logProvider url.URL, timeout time.Duration) http.HandlerF
log.Printf("LogProxy: client connection closed") log.Printf("LogProxy: client connection closed")
return return
} }
default:
http.Error(w, fmt.Sprintf("unknown log request error (%v)", logResp.StatusCode), http.StatusInternalServerError)
}
return return
} }