From 4f57f4850cf236995d764ac147c2822b2b85b74b Mon Sep 17 00:00:00 2001 From: antklim Date: Fri, 30 Jul 2021 16:57:38 +1000 Subject: [PATCH] fix: fixing linter error in dsl/pact --- dsl/pact.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/dsl/pact.go b/dsl/pact.go index 3b0280fa9..1c6aa463a 100644 --- a/dsl/pact.go +++ b/dsl/pact.go @@ -488,9 +488,13 @@ func stateHandlerMiddleware(stateHandlers types.StateHandlers) proxy.Middleware return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path == providerStatesSetupPath { - var s *types.ProviderState + var s types.ProviderState decoder := json.NewDecoder(r.Body) - decoder.Decode(&s) + if err := decoder.Decode(&s); err != nil { + log.Printf("[ERROR] failed to decode provider state: %v", err) + w.WriteHeader(http.StatusBadRequest) + return + } // Setup any provider state for _, state := range s.States { @@ -582,12 +586,14 @@ var messageVerificationHandler = func(messageHandlers MessageHandlers, stateHand resBody, errM := json.Marshal(wrappedResponse) if errM != nil { w.WriteHeader(http.StatusServiceUnavailable) - log.Println("[ERROR] error marshalling objcet:", errM) + log.Println("[ERROR] error marshalling object:", errM) return } w.WriteHeader(http.StatusOK) - w.Write(resBody) + if _, err := w.Write(resBody); err != nil { + log.Println("[ERROR] error writing response:", err) + } } }