@@ 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,7 325,13 @@ func (br *bridge) publish(n *notification) error {
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
- return fmt.Errorf("ntfy: received status code %d", resp.StatusCode)
+ 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