feat: notifications retry mechanism and improved error formatting

This commit is contained in:
yusing
2025-05-03 14:30:40 +08:00
parent 2fe4fef779
commit 82c829de18
9 changed files with 146 additions and 54 deletions

View File

@@ -3,7 +3,6 @@ package notif
import (
_ "embed"
"encoding/json"
"fmt"
"io"
"net/http"
"strings"
@@ -88,16 +87,13 @@ func (webhook *Webhook) GetMIMEType() string {
return webhook.MIMEType
}
// makeRespError implements Provider.
func (webhook *Webhook) makeRespError(resp *http.Response) error {
body, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("%s status %d, failed to read body: %w", webhook.Name, resp.StatusCode, err)
// fmtError implements Provider.
func (webhook *Webhook) fmtError(respBody io.Reader) error {
body, err := io.ReadAll(respBody)
if err != nil || len(body) == 0 {
return ErrUnknownError
}
if len(body) > 0 {
return fmt.Errorf("%s status %d: %s", webhook.Name, resp.StatusCode, body)
}
return fmt.Errorf("%s status %d", webhook.Name, resp.StatusCode)
return rawError(body)
}
func (webhook *Webhook) MarshalMessage(logMsg *LogMessage) ([]byte, error) {