mirror of
https://github.com/Li4n0/revsuit.git
synced 2026-09-26 16:41:53 +08:00
fix some bug and standardize the code (#2)
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/li4n0/revsuit/internal/record"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var _ Bot = (*Slack)(nil)
|
||||
@@ -67,16 +68,16 @@ func (d *Slack) buildPayload(r record.Record) string {
|
||||
}
|
||||
|
||||
func (d *Slack) notice(r record.Record) error {
|
||||
resp, err := http.DefaultClient.Post(d.URL, "application/json", strings.NewReader(d.buildPayload(r)))
|
||||
resp, err := http.Post(d.URL, "application/json", strings.NewReader(d.buildPayload(r)))
|
||||
if err != nil {
|
||||
return fmt.Errorf("HTTP request: %v", err)
|
||||
return errors.Wrap(err, "HTTP request")
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode/100 != 2 {
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return fmt.Errorf("read HTTP response body: %v", err)
|
||||
return errors.Wrap(err, "read HTTP response body")
|
||||
}
|
||||
return fmt.Errorf("non-success response status code %d with body: %s", resp.StatusCode, data)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user