Skip to content

Commit

Permalink
Check error before attempting to use request
Browse files Browse the repository at this point in the history
  • Loading branch information
jsvensson committed May 18, 2021
1 parent 1019fec commit 09ba276
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

Expand Down

0 comments on commit 09ba276

Please # to comment.