publish: Try to decode ntfy error string
This commit is contained in:
parent
7efc6cdbc2
commit
dc9078c3f5
1 changed files with 11 additions and 1 deletions
10
main.go
10
main.go
|
@ -58,6 +58,10 @@ type notification struct {
|
|||
status string
|
||||
}
|
||||
|
||||
type ntfyError struct {
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
func (br *bridge) singleAlertNotifications(p *payload) []*notification {
|
||||
var notifications []*notification
|
||||
for _, alert := range p.Alerts {
|
||||
|
@ -321,9 +325,15 @@ func (br *bridge) publish(n *notification) error {
|
|||
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
var ntfyError ntfyError
|
||||
if err := json.NewDecoder(resp.Body).Decode(&ntfyError); err != nil {
|
||||
br.logger.Debugf("Publish: failed to decode error: %v", err)
|
||||
return fmt.Errorf("ntfy: received status code %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
return fmt.Errorf("ntfy: %s (status code %d)", ntfyError.Error, resp.StatusCode)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue