From 09ba2760c1e285bb89544a23c3ed6fdc507a496e Mon Sep 17 00:00:00 2001 From: Johan Svensson Date: Tue, 18 May 2021 19:14:58 +0200 Subject: [PATCH] Check error before attempting to use request --- module.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/module.go b/module.go index 3e983cc..a2dafb5 100644 --- a/module.go +++ b/module.go @@ -81,12 +81,14 @@ func newModule(filename string) (*module, error) { } func (m *module) newRequest(baseURL, path string) (*http.Request, error) { - req, err := http.NewRequest( m.Request.Method, baseURL+path, bytes.NewBuffer([]byte(m.Request.Body)), ) + if err != nil { + return nil, err + } for _, h := range m.Request.Headers { parts := strings.SplitN(h, ":", 2) @@ -102,10 +104,6 @@ func (m *module) newRequest(baseURL, path string) (*http.Request, error) { req.Header.Set(k, v) } - if err != nil { - return nil, err - } - return req, nil }