diff --git a/plugins/traefik/pkg/strategy/strategy.go b/plugins/traefik/pkg/strategy/strategy.go index 5a60a90..d695234 100644 --- a/plugins/traefik/pkg/strategy/strategy.go +++ b/plugins/traefik/pkg/strategy/strategy.go @@ -1,10 +1,9 @@ package strategy import ( + "encoding/json" "errors" - "io/ioutil" "net/http" - "strings" "time" ) @@ -13,6 +12,11 @@ var netClient = &http.Client{ Timeout: time.Second * 2, } +type SablierResponse struct { + State string `json:"state"` + Error string `json:"error"` +} + type Strategy interface { ServeHTTP(rw http.ResponseWriter, req *http.Request) } @@ -25,15 +29,16 @@ func getServiceStatus(request string) (string, error) { return "error", err } - defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + decoder := json.NewDecoder(resp.Body) + var response SablierResponse + err = decoder.Decode(&response) if err != nil { - return "parsing error", err + return "error from ondemand service", err } if resp.StatusCode >= 400 { - return "error from ondemand service", errors.New(string(body)) + return "error from ondemand service", errors.New(response.Error) } - return strings.TrimSuffix(string(body), "\n"), nil + return response.State, nil }