return an empty list instead of an error if no result

Signed-off-by: Hadi <[email protected]>
This commit is contained in:
Hadi
2025-09-25 19:15:16 +02:00
parent aa44e44409
commit e74f69daf7
3 changed files with 12 additions and 1 deletions
+4 -1
View File
@@ -58,12 +58,15 @@ func main() {
}
profiles, err := gravatar_recon.GetGravatarProfiles(email)
if err != nil {
if err != nil || profiles == nil {
log.Fatal("Failed to get Gravatar profile", "err", err)
}
if !*silent {
utils.Header()
if len(*profiles) == 0 {
utils.PrintNoResultFound()
}
for _, profile := range *profiles {
utils.PrintTitle(profile.PreferredUser + ":")
if *printAvatar {
+4
View File
@@ -91,6 +91,10 @@ func GetGravatarProfiles(email string) (*[]GravatarProfile, error) {
}
defer resp.Body.Close()
if resp.StatusCode == 404 {
return &[]GravatarProfile{}, nil
}
if resp.StatusCode != 200 {
return nil, fmt.Errorf("no gravatar profile found (status %d)", resp.StatusCode)
}
+4
View File
@@ -133,6 +133,10 @@ func PrintTitle(title string) {
fmt.Println(titleStyle.Render(title) + "\n")
}
func PrintNoResultFound() {
fmt.Println(titleStyle.Render("No result found"))
}
func PrintAvatar(url string) {
if url == "" {
return