@@ -5,8 +5,10 @@ import (
5
5
"crypto/sha256"
6
6
"errors"
7
7
"fmt"
8
+ "io"
8
9
"os"
9
10
"runtime"
11
+ "strings"
10
12
"time"
11
13
12
14
"github.com/PagerDuty/go-pagerduty"
@@ -23,6 +25,9 @@ func NewPagerDutyAlerter(cfg *service.PagerDutyAlerting) (*PagerDuty, error) {
23
25
client : pagerduty .NewClient (cfg .ApiKey ),
24
26
routingKey : cfg .RoutingKey ,
25
27
}
28
+ if notifier .client != nil {
29
+ notifier .client .SetDebugFlag (pagerduty .DebugCaptureLastResponse )
30
+ }
26
31
if err := notifier .ping (); err != nil {
27
32
return nil , err
28
33
}
@@ -69,9 +74,20 @@ func (pd *PagerDuty) AlertError(e error) error {
69
74
}
70
75
71
76
ctx := context .Background ()
72
- _ , err = pd .client .ManageEventWithContext (ctx , event )
77
+ v2EventResponse , err : = pd .client .ManageEventWithContext (ctx , event )
73
78
if err != nil {
74
- return fmt .Errorf ("creating event in PagerDuty: %v" , err )
79
+ var httpRespBody []byte
80
+ httpResp , _ := pd .client .LastAPIResponse ()
81
+ if httpResp != nil && httpResp .Body != nil {
82
+ httpRespBody , _ = io .ReadAll (httpResp .Body )
83
+ }
84
+ var outErr error
85
+ if v2EventResponse != nil {
86
+ outErr = fmt .Errorf ("%s problem creating PagerDuty event caused by %s: %s" , v2EventResponse .Status , v2EventResponse .Message , strings .Join (v2EventResponse .Errors , ", " ))
87
+ } else {
88
+ outErr = fmt .Errorf ("unexpected response of %s from creating event in PagerDuty: %v" , string (httpRespBody ), err )
89
+ }
90
+ return outErr
75
91
}
76
92
77
93
return nil
0 commit comments