Skip to content

Commit

Permalink
fix: provide an error message in the dashboard when WHOIS cache misses
Browse files Browse the repository at this point in the history
  • Loading branch information
nwesterhausen committed Apr 9, 2024
1 parent b366f4c commit 8489933
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
11 changes: 9 additions & 2 deletions handlers/whois.handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handlers
import (
"errors"

"github.com/a-h/templ"
"github.com/labstack/echo/v4"
"github.com/nwesterhausen/domain-monitor/service"
"github.com/nwesterhausen/domain-monitor/views/domains"
Expand All @@ -25,8 +26,14 @@ func (h *WhoisHandler) GetCard(c echo.Context) error {
return errors.New("invalid domain to fetch (FQDN required)")
}

whois := h.WhoisService.GetWhois(fqdn)
card := domains.WhoisDetail(whois)
var card templ.Component
whois, err := h.WhoisService.GetWhois(fqdn)

if err != nil {
card = domains.WhoisError(err)
} else {
card = domains.WhoisDetail(whois)
}

return View(c, card)
}
9 changes: 5 additions & 4 deletions service/whois.service.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package service

import (
"errors"
"log"

"github.com/nwesterhausen/domain-monitor/configuration"
Expand All @@ -14,15 +15,15 @@ func NewWhoisService(store configuration.WhoisCacheStorage) *ServicesWhois {
return &ServicesWhois{store: store}
}

func (s *ServicesWhois) GetWhois(fqdn string) configuration.WhoisCache {
func (s *ServicesWhois) GetWhois(fqdn string) (configuration.WhoisCache, error) {
for _, entry := range s.store.FileContents.Entries {
if entry.FQDN == fqdn {
return entry
return entry, nil
}
}
log.Println("WHOIS entry cache miss for", fqdn)
log.Println("🙅 WHOIS entry cache miss for", fqdn)

return configuration.WhoisCache{}
return configuration.WhoisCache{}, errors.New("WHOIS entry not found")
}

func (s *ServicesWhois) MarkAlertSent(fqdn string, alert configuration.Alert) bool {
Expand Down
10 changes: 5 additions & 5 deletions views/domains/domain-dashboard.templ
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/nwesterhausen/domain-monitor/configuration"
"strings"
"time"
"fmt"

"github.com/hako/durafmt"
)
Expand Down Expand Up @@ -32,12 +33,11 @@ templ DomainCards(domains []configuration.Domain) {
</div>
}

templ WhoisDetail(whois configuration.WhoisCache) {
if (configuration.WhoisCache{}) == whois {
<div class="text-center text-2xl">No WHOIS data available</div>
return
}
templ WhoisError(err error) {
<div class="text-error">{ fmt.Sprintf("WHOIS Cache Miss. %v", err) }</div>
}

templ WhoisDetail(whois configuration.WhoisCache) {
<div class="flex flex-col">
@WhoisDetailItem("Registrar", whois.WhoisInfo.Registrar.Name)
@WhoisDetailItem("Name Servers", strings.Join(whois.WhoisInfo.Domain.NameServers, ", "))
Expand Down

0 comments on commit 8489933

Please sign in to comment.