Skip to content

Commit 6f8e2cb

Browse files
authored
Merge pull request #9 from NETWAYS/feature/improved-errormsg
Improve error messages to be more expressive
2 parents d254eab + 093abf5 commit 6f8e2cb

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

cmd/root.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func sendNotification(_ *cobra.Command, _ []string) {
110110
notificationType, err := icingadsl.ParseNotificationType(cliConfig.IcingaNotificationType)
111111

112112
if err != nil {
113-
check.ExitError(err)
113+
check.ExitError(fmt.Errorf("unsupported notification type. Currently supported: Problem/Recovery/Acknowledgement"))
114114
}
115115

116116
// Creating an client and connecting to the API
@@ -165,7 +165,7 @@ func sendNotification(_ *cobra.Command, _ []string) {
165165
case icingadsl.FlappingEnd:
166166
// Currently no implemented
167167
default:
168-
check.ExitError(fmt.Errorf("unsupported notification type"))
168+
check.ExitError(fmt.Errorf("unsupported notification type. Currently supported: Problem/Recovery/Acknowledgement"))
169169
}
170170

171171
if notificationErr != nil {
@@ -227,7 +227,7 @@ func handleAcknowledgeNotification(ctx context.Context, c *client.Client, ticket
227227
// If no Zammad Ticket exists, we cannot add an article and thus return an error
228228
// and notify the user
229229
if ticket.ID == 0 {
230-
return fmt.Errorf("no open or new ticket found to add acknowledgement")
230+
return fmt.Errorf("no open or new ticket found to add acknowledgement article to")
231231
}
232232

233233
a := zammad.Article{
@@ -257,7 +257,7 @@ func handleAcknowledgeNotification(ctx context.Context, c *client.Client, ticket
257257
// If ticket is closed, reopens the ticket with an article
258258
func handleRecoveryNotification(ctx context.Context, c *client.Client, ticket zammad.Ticket) error {
259259
if ticket.ID == 0 {
260-
return fmt.Errorf("no open or new ticket found to add recovery")
260+
return fmt.Errorf("no open or new ticket found to add recovery article to")
261261
}
262262

263263
a := zammad.Article{

internal/client/client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ func (c *Client) SearchTickets(ctx context.Context, hostname, service string) ([
6666

6767
defer resp.Body.Close()
6868

69+
if resp.StatusCode == http.StatusUnauthorized {
70+
return nil, fmt.Errorf("authentication failed for %s", c.URL.String())
71+
}
72+
6973
var result zammad.TicketSearchResult
7074

7175
err = json.NewDecoder(resp.Body).Decode(&result)

0 commit comments

Comments
 (0)