Skip to content

Commit

Permalink
Whois error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
alex27riva committed Dec 2, 2024
1 parent 69fcf17 commit b9864fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 8 additions & 2 deletions cmd/whois.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,14 @@ var whoisCmd = &cobra.Command{
os.Exit(1)
}

whoisData := apis.GetWhoisData(target)
displayData(*whoisData)
whoisData, err := apis.GetWhoisData(target)
if err != nil {
color.Red("An error has occured.")
} else {
displayData(*whoisData)

}

},
}

Expand Down
8 changes: 2 additions & 6 deletions internal/apis/whodat.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package apis

import (
"fmt"
"log"
"soc-cli/internal/util"
)

Expand Down Expand Up @@ -64,15 +63,12 @@ type DomainInfo struct {
Technical Contact `json:"technical"`
}

func GetWhoisData(domain string) *DomainInfo {
func GetWhoisData(domain string) (*DomainInfo, error) {
apiUrl := fmt.Sprintf(whodatAPIURL, domain)

var whois DomainInfo

err := util.MakeGETRequest(apiUrl, nil, &whois)
if err != nil {
log.Fatalf("Error fetching whodat API: %v", err)
}

return &whois
return &whois, err
}

0 comments on commit b9864fc

Please sign in to comment.