NotifyError sends an error notification through the configured notification system. It logs the error locally and sends a notification via Slack (if configured). Parameters: - systemError: The error to notify. This function runs the notification process asynchronously using a goroutine to avoid bl
(systemError error)
| 116 | // |
| 117 | // This function runs the notification process asynchronously using a goroutine to avoid blocking. |
| 118 | func NotifyError(systemError error) { |
| 119 | go func(systemError error) { |
| 120 | // Log the error locally using logrus |
| 121 | logrus.Error(systemError) |
| 122 | |
| 123 | // Fetch the configuration |
| 124 | conf, err := config.Fetch() |
| 125 | if err != nil { |
| 126 | logrus.Error(err) |
| 127 | return |
| 128 | } |
| 129 | |
| 130 | // If Slack is configured, send the error notification to Slack |
| 131 | if conf.Notification.Slack.WebhookUrl != "" { |
| 132 | SlackNotification(systemError) |
| 133 | } |
| 134 | |
| 135 | // If a webhook sender is registered and webhook URL is configured, send the webhook |
| 136 | if webhookSender != nil && conf.Notification.Webhook.Url != "" { |
| 137 | payload := map[string]interface{}{ |
| 138 | "error": systemError.Error(), |
| 139 | "time": time.Now(), |
| 140 | } |
| 141 | err := webhookSender("system.error", payload) |
| 142 | if err != nil { |
| 143 | logrus.Errorf("Error sending webhook notification: %v", err) |
| 144 | } |
| 145 | } |
| 146 | }(systemError) |
| 147 | } |
no test coverage detected