From 5637adf60185abf75f30c7259684eb63804b3e43 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Tue, 10 Apr 2018 08:56:44 -0700 Subject: [PATCH] Handle NewRelic connectivity errors --- newrelic/widget.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/newrelic/widget.go b/newrelic/widget.go index 83f09cd8..ba935937 100644 --- a/newrelic/widget.go +++ b/newrelic/widget.go @@ -34,14 +34,26 @@ func (widget *Widget) Refresh() { return } - app, _ := Application() - deploys, _ := Deployments() + app, appErr := Application() + deploys, depErr := Deployments() - widget.View.SetTitle(fmt.Sprintf(" New Relic: [green]%s[white] ", app.Name)) + appName := "error" + if appErr == nil { + appName = app.Name + } + + widget.View.SetTitle(fmt.Sprintf(" New Relic: [green]%s[white] ", appName)) widget.RefreshedAt = time.Now() widget.View.Clear() - fmt.Fprintf(widget.View, "%s", widget.contentFrom(deploys)) + + if depErr != nil { + widget.View.SetWrap(true) + fmt.Fprintf(widget.View, "%s", depErr) + } else { + widget.View.SetWrap(false) + fmt.Fprintf(widget.View, "%s", widget.contentFrom(deploys)) + } } /* -------------------- Unexported Functions -------------------- */