From dc9078c3f524d3e802f7fab43e8a539e249a224f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Fri, 7 Jul 2023 23:20:03 +0200 Subject: [PATCH] publish: Try to decode ntfy error string --- main.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index defc73e..8f97b64 100644 --- a/main.go +++ b/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,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