Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions courier/http_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package courier

import (
"bytes"
"context"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -105,9 +106,11 @@ func (c *httpChannel) Dispatch(ctx context.Context, msg Message) (err error) {
}

err = errors.Errorf(
"unable to dispatch mail delivery because upstream server replied with status code %d",
res.StatusCode,
"unable to dispatch mail delivery because upstream server replied with status code %d and body: %s",
res.StatusCode,
bytes.NewBuffer(x.MustReadAll(res.Body)).String(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please properly handle the error of the stream reader here (in this case ignore the error and log an empty body) as otherwise this can panic. Otherwise LGTM. Also you don‘t need to create a buffer.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're also never closing the response body here. And we must have an io.LimitReader to avoid reading unbounded data.

)

logger.
WithError(err).
Error("sending mail via HTTP failed.")
Expand Down