Skip to content

Commit

Permalink
dont check error when creating an http request with known content
Browse files Browse the repository at this point in the history
  • Loading branch information
nicpottier committed Feb 27, 2018
1 parent b74a636 commit 7167274
Show file tree
Hide file tree
Showing 30 changed files with 34 additions and 75 deletions.
4 changes: 1 addition & 3 deletions backends/rapidpro/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,11 @@ func downloadMediaToS3(ctx context.Context, b *backend, channel courier.Channel,
}

if req == nil {

// first fetch our media
req, err = http.NewRequest("GET", mediaURL, nil)
req, err = http.NewRequest(http.MethodGet, mediaURL, nil)
if err != nil {
return "", err
}

}

resp, err := utils.GetHTTPClient().Do(req)
Expand Down
5 changes: 1 addition & 4 deletions chatbase/chatbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ func SendChatbaseMessage(apiKey string, apiVersion string, messageType string, u
return err
}

req, err := http.NewRequest(http.MethodPost, chatbaseAPIURL, bytes.NewReader(jsonBody))
if err != nil {
return err
}
req, _ := http.NewRequest(http.MethodPost, chatbaseAPIURL, bytes.NewReader(jsonBody))
req.Header.Set("Content-Type", "application/json")

_, err = utils.MakeHTTPRequest(req)
Expand Down
2 changes: 1 addition & 1 deletion handlers/africastalking/africastalking.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (h *handler) SendMsg(_ context.Context, msg courier.Msg) (courier.MsgStatus
form["from"] = []string{msg.Channel().Address()}
}

req, err := http.NewRequest(http.MethodPost, sendURL, strings.NewReader(form.Encode()))
req, _ := http.NewRequest(http.MethodPost, sendURL, strings.NewReader(form.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Accept", "application/json")
req.Header.Set("apikey", apiKey)
Expand Down
2 changes: 1 addition & 1 deletion handlers/arabiacell/arabiacell.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (h *handler) SendMsg(_ context.Context, msg courier.Msg) (courier.MsgStatus
"chargingLevel": []string{chargingLevel},
}

req, err := http.NewRequest(http.MethodPost, sendURL, strings.NewReader(form.Encode()))
req, _ := http.NewRequest(http.MethodPost, sendURL, strings.NewReader(form.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Accept", "application/xml")
rr, err := utils.MakeHTTPRequest(req)
Expand Down
2 changes: 1 addition & 1 deletion handlers/blackmyna/blackmyna.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
"message": []string{handlers.GetTextAndAttachments(msg)},
}

req, err := http.NewRequest(http.MethodPost, sendURL, strings.NewReader(form.Encode()))
req, _ := http.NewRequest(http.MethodPost, sendURL, strings.NewReader(form.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.SetBasicAuth(username, password)
rr, err := utils.MakeHTTPRequest(req)
Expand Down
2 changes: 1 addition & 1 deletion handlers/clickatell/clickatell.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
partSendURL, _ := url.Parse(sendURL)
partSendURL.RawQuery = form.Encode()

req, err := http.NewRequest(http.MethodGet, partSendURL.String(), nil)
req, _ := http.NewRequest(http.MethodGet, partSendURL.String(), nil)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Accept", "application/json")
rr, err := utils.MakeHTTPRequest(req)
Expand Down
2 changes: 1 addition & 1 deletion handlers/dart/dart.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
partSendURL, _ := url.Parse(h.sendURL)
partSendURL.RawQuery = form.Encode()

req, err := http.NewRequest(http.MethodGet, partSendURL.String(), nil)
req, _ := http.NewRequest(http.MethodGet, partSendURL.String(), nil)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
rr, err := utils.MakeHTTPRequest(req)

Expand Down
2 changes: 1 addition & 1 deletion handlers/dmark/dmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
"dlr_url": []string{dlrURL},
}

req, err := http.NewRequest(http.MethodPost, sendURL, strings.NewReader(form.Encode()))
req, _ := http.NewRequest(http.MethodPost, sendURL, strings.NewReader(form.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Accept", "application/json")
req.Header.Set("Authorization", fmt.Sprintf("Token %s", auth))
Expand Down
2 changes: 1 addition & 1 deletion handlers/facebook/facebook.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
return status, err
}

req, err := http.NewRequest(http.MethodPost, msgURL.String(), bytes.NewReader(jsonBody))
req, _ := http.NewRequest(http.MethodPost, msgURL.String(), bytes.NewReader(jsonBody))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
rr, err := utils.MakeHTTPRequest(req)
Expand Down
2 changes: 1 addition & 1 deletion handlers/firebase/firebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
return nil, err
}

req, err := http.NewRequest(http.MethodPost, sendURL, bytes.NewReader(jsonPayload))
req, _ := http.NewRequest(http.MethodPost, sendURL, bytes.NewReader(jsonPayload))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
req.Header.Set("Authorization", fmt.Sprintf("key=%s", fcmKey))
Expand Down
5 changes: 1 addition & 4 deletions handlers/globe/globe.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,9 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
json.NewEncoder(requestBody).Encode(payload)

// build our request
req, err := http.NewRequest(http.MethodPost, fmt.Sprintf(sendURL, msg.Channel().Address()), requestBody)
req, _ := http.NewRequest(http.MethodPost, fmt.Sprintf(sendURL, msg.Channel().Address()), requestBody)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
if err != nil {
return nil, err
}

rr, err := utils.MakeHTTPRequest(req)
log := courier.NewChannelLogFromRR("Message Sent", msg.Channel(), msg.ID(), rr).WithError("Message Send Error", err)
Expand Down
2 changes: 1 addition & 1 deletion handlers/infobip/infobip.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
}

// build our request
req, err := http.NewRequest(http.MethodPost, sendURL, requestBody)
req, _ := http.NewRequest(http.MethodPost, sendURL, requestBody)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
req.SetBasicAuth(username, password)
Expand Down
17 changes: 4 additions & 13 deletions handlers/jiochat/jiochat.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (h *handler) fetchAccessToken(channel courier.Channel) error {
return err
}

req, err := http.NewRequest(http.MethodPost, tokenURL.String(), bytes.NewReader(jsonBody))
req, _ := http.NewRequest(http.MethodPost, tokenURL.String(), bytes.NewReader(jsonBody))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
rr, err := utils.MakeHTTPRequest(req)
Expand Down Expand Up @@ -255,13 +255,11 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
json.NewEncoder(requestBody).Encode(jcMsg)

// build our request
req, err := http.NewRequest(http.MethodPost, fmt.Sprintf("%s/%s", sendURL, "custom/custom_send.action"), requestBody)
req, _ := http.NewRequest(http.MethodPost, fmt.Sprintf("%s/%s", sendURL, "custom/custom_send.action"), requestBody)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", accessToken))
if err != nil {
return nil, err
}

rr, err := utils.MakeHTTPRequest(req)

Expand Down Expand Up @@ -294,11 +292,8 @@ func (h *handler) DescribeURN(ctx context.Context, channel courier.Channel, urn
reqURL, _ := url.Parse(fmt.Sprintf("%s/%s", sendURL, "user/info.action"))
reqURL.RawQuery = form.Encode()

req, err := http.NewRequest(http.MethodGet, reqURL.String(), nil)
req, _ := http.NewRequest(http.MethodGet, reqURL.String(), nil)
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", accessToken))
if err != nil {
return nil, err
}

rr, err := utils.MakeHTTPRequest(req)
if err != nil {
Expand All @@ -325,11 +320,7 @@ func (h *handler) BuildDownloadMediaRequest(ctx context.Context, b courier.Backe
}

// first fetch our media
req, err := http.NewRequest(http.MethodGet, parsedURL.String(), nil)
req, _ := http.NewRequest(http.MethodGet, parsedURL.String(), nil)
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", accessToken))
if err != nil {
return nil, err
}

return req, nil
}
2 changes: 1 addition & 1 deletion handlers/junebug/junebug.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
return status, err
}

req, err := http.NewRequest(http.MethodPost, sendURL, bytes.NewReader(jsonBody))
req, _ := http.NewRequest(http.MethodPost, sendURL, bytes.NewReader(jsonBody))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
req.SetBasicAuth(username, password)
Expand Down
4 changes: 0 additions & 4 deletions handlers/kannel/kannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,6 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
verifySSL, _ := verifySSLStr.(bool)

req, err := http.NewRequest(http.MethodGet, sendURL, nil)
if err != nil {
return nil, err
}

var rr *utils.RequestResponse

if verifySSL {
Expand Down
5 changes: 1 addition & 4 deletions handlers/line/line.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,10 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
json.NewEncoder(requestBody).Encode(payload)

// build our request
req, err := http.NewRequest(http.MethodPost, sendURL, requestBody)
req, _ := http.NewRequest(http.MethodPost, sendURL, requestBody)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", authToken))
if err != nil {
return nil, err
}

rr, err := utils.MakeHTTPRequest(req)
// record our status and log
Expand Down
5 changes: 1 addition & 4 deletions handlers/m3tech/m3tech.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat

msgURL, _ := url.Parse(sendURL)
msgURL.RawQuery = params.Encode()
req, err := http.NewRequest(http.MethodGet, msgURL.String(), nil)
if err != nil {
return nil, err
}
req, _ := http.NewRequest(http.MethodGet, msgURL.String(), nil)

rr, err := utils.MakeHTTPRequest(req)
status.AddLog(courier.NewChannelLogFromRR("Message Sent", msg.Channel(), msg.ID(), rr).WithError("Message Send Error", err))
Expand Down
6 changes: 1 addition & 5 deletions handlers/mblox/mblox.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,11 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
json.NewEncoder(requestBody).Encode(payload)

// build our request
req, err := http.NewRequest(http.MethodPost, fmt.Sprintf("%s/%s/batches", sendURL, username), requestBody)
req, _ := http.NewRequest(http.MethodPost, fmt.Sprintf("%s/%s/batches", sendURL, username), requestBody)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", password))

if err != nil {
return nil, err
}

rr, err := utils.MakeHTTPRequest(req)
log := courier.NewChannelLogFromRR("Message Sent", msg.Channel(), msg.ID(), rr).WithError("Message Send Error", err)
status.AddLog(log)
Expand Down
5 changes: 1 addition & 4 deletions handlers/mtarget/mtarget.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat

msgURL, _ := url.Parse(sendURL)
msgURL.RawQuery = params.Encode()
req, err := http.NewRequest(http.MethodPost, msgURL.String(), nil)
if err != nil {
return nil, err
}
req, _ := http.NewRequest(http.MethodPost, msgURL.String(), nil)

rr, err := utils.MakeHTTPRequest(req)
log := courier.NewChannelLogFromRR("Message Sent", msg.Channel(), msg.ID(), rr).WithError("Message Send Error", err)
Expand Down
2 changes: 1 addition & 1 deletion handlers/nexmo/nexmo.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
"type": []string{textType},
}

req, err := http.NewRequest(http.MethodPost, sendURL, strings.NewReader(form.Encode()))
req, _ := http.NewRequest(http.MethodPost, sendURL, strings.NewReader(form.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")

var rr *utils.RequestResponse
Expand Down
2 changes: 1 addition & 1 deletion handlers/shaqodoon/shaqodoon.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
encodedForm := form.Encode()
sendURL = fmt.Sprintf("%s?%s", sendURL, encodedForm)

req, err := http.NewRequest(http.MethodGet, sendURL, nil)
req, _ := http.NewRequest(http.MethodGet, sendURL, nil)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
rr, err := utils.MakeInsecureHTTPRequest(req)

Expand Down
2 changes: 1 addition & 1 deletion handlers/smscentral/smscentral.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
"content": []string{handlers.GetTextAndAttachments(msg)},
}

req, err := http.NewRequest(http.MethodPost, sendURL, strings.NewReader(form.Encode()))
req, _ := http.NewRequest(http.MethodPost, sendURL, strings.NewReader(form.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
rr, err := utils.MakeHTTPRequest(req)

Expand Down
2 changes: 1 addition & 1 deletion handlers/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
}

// build our request
req, err := http.NewRequest(http.MethodPost, sendURL, requestBody)
req, _ := http.NewRequest(http.MethodPost, sendURL, requestBody)
req.Header.Set("Content-Type", "application/xml; charset=utf8")
req.SetBasicAuth(username, password)
rr, err := utils.MakeHTTPRequest(req)
Expand Down
8 changes: 2 additions & 6 deletions handlers/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (h *handler) sendMsgPart(msg courier.Msg, token string, path string, form u
}

sendURL := fmt.Sprintf("%s/bot%s/%s", apiURL, token, path)
req, err := http.NewRequest(http.MethodPost, sendURL, strings.NewReader(form.Encode()))
req, _ := http.NewRequest(http.MethodPost, sendURL, strings.NewReader(form.Encode()))
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

rr, err := utils.MakeHTTPRequest(req)
Expand Down Expand Up @@ -286,13 +286,9 @@ func resolveFileID(channel courier.Channel, fileID string) (string, error) {
form := url.Values{}
form.Set("file_id", fileID)

req, err := http.NewRequest(http.MethodPost, fileURL, strings.NewReader(form.Encode()))
req, _ := http.NewRequest(http.MethodPost, fileURL, strings.NewReader(form.Encode()))
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

if err != nil {
return "", err
}

rr, err := utils.MakeHTTPRequest(req)
if err != nil {
return "", err
Expand Down
2 changes: 1 addition & 1 deletion handlers/twilio/twilio.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
return nil, err
}

req, err := http.NewRequest(http.MethodPost, sendURL, strings.NewReader(form.Encode()))
req, _ := http.NewRequest(http.MethodPost, sendURL, strings.NewReader(form.Encode()))
req.SetBasicAuth(accountSID, accountToken)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Accept", "application/json")
Expand Down
2 changes: 1 addition & 1 deletion handlers/twitter/twitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
return status, err
}

req, err := http.NewRequest(http.MethodPost, sendURL, bytes.NewReader(jsonBody))
req, _ := http.NewRequest(http.MethodPost, sendURL, bytes.NewReader(jsonBody))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
rr, err := utils.MakeHTTPRequestWithClient(req, client)
Expand Down
2 changes: 1 addition & 1 deletion handlers/viber/viber.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
}

// build our request
req, err := http.NewRequest(http.MethodPost, sendURL, requestBody)
req, _ := http.NewRequest(http.MethodPost, sendURL, requestBody)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
rr, err := utils.MakeHTTPRequest(req)
Expand Down
2 changes: 1 addition & 1 deletion handlers/whatsapp/whatsapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
return status, err
}

req, err := http.NewRequest(http.MethodPost, sendURL, bytes.NewReader(jsonBody))
req, _ := http.NewRequest(http.MethodPost, sendURL, bytes.NewReader(jsonBody))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
req.SetBasicAuth(username, password)
Expand Down
3 changes: 2 additions & 1 deletion handlers/yo/yo.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
sendURL, _ := url.Parse(sendURL)
sendURL.RawQuery = form.Encode()

req, err := http.NewRequest(http.MethodGet, sendURL.String(), nil)
req, _ := http.NewRequest(http.MethodGet, sendURL.String(), nil)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")

rr, err := utils.MakeHTTPRequest(req)
log := courier.NewChannelLogFromRR("Message Sent", msg.Channel(), msg.ID(), rr).WithError("Message Send Error", err)
status.AddLog(log)
Expand Down
6 changes: 1 addition & 5 deletions librato/librato.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@ func (c *Sender) flush(count int) {
return
}

req, err := http.NewRequest("POST", libratoEndpoint, bytes.NewReader(encoded))
if err != nil {
logrus.WithField("comp", "librato").WithError(err).Error("error sending librato metrics")
return
}
req, _ := http.NewRequest("POST", libratoEndpoint, bytes.NewReader(encoded))
req.SetBasicAuth(c.username, c.token)
req.Header.Set("Content-Type", "application/json")
_, err = utils.MakeHTTPRequest(req)
Expand Down

0 comments on commit 7167274

Please sign in to comment.