Deretardify some of the error handling
woooooooow string comparisons really......... great job clanker.......
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,3 +6,4 @@ postgres_data
|
||||
dbgate-data
|
||||
clickhouse_data
|
||||
*.exe
|
||||
.cache
|
||||
|
||||
61
enrich.go
61
enrich.go
@@ -2,9 +2,11 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -283,7 +285,11 @@ func flattenVictim(ctx context.Context, db DB, victim Victim, flat *FlatKillmail
|
||||
flog.Debug("Fetching character name for ID %d", victim.CharacterID)
|
||||
name, err := getCharacterName(victim.CharacterID)
|
||||
if err != nil {
|
||||
flog.Info("Character not found (deleted?): %v", err)
|
||||
if errors.Is(err, errNotFound) {
|
||||
flog.Debug("Character not found (deleted?)")
|
||||
} else {
|
||||
flog.Error("Failed to get character name: %v", err)
|
||||
}
|
||||
flat.VictimCharacterName = ""
|
||||
} else {
|
||||
flat.VictimCharacterName = name
|
||||
@@ -299,7 +305,11 @@ func flattenVictim(ctx context.Context, db DB, victim Victim, flat *FlatKillmail
|
||||
flog.Debug("Fetching corporation name for ID %d", victim.CorporationID)
|
||||
name, err := getCorporationName(victim.CorporationID)
|
||||
if err != nil {
|
||||
flog.Debug("Corporation not found (deleted?): %v", err)
|
||||
if errors.Is(err, errNotFound) {
|
||||
flog.Debug("Corporation not found (deleted?)")
|
||||
} else {
|
||||
flog.Error("Failed to get corporation name: %v", err)
|
||||
}
|
||||
flat.VictimCorporationName = ""
|
||||
} else {
|
||||
flat.VictimCorporationName = name
|
||||
@@ -315,7 +325,11 @@ func flattenVictim(ctx context.Context, db DB, victim Victim, flat *FlatKillmail
|
||||
flog.Debug("Fetching alliance name for ID %d", victim.AllianceID)
|
||||
name, err := getAllianceName(victim.AllianceID)
|
||||
if err != nil {
|
||||
flog.Debug("Alliance not found (deleted?): %v", err)
|
||||
if errors.Is(err, errNotFound) {
|
||||
flog.Debug("Alliance not found (deleted?)")
|
||||
} else {
|
||||
flog.Error("Failed to get alliance name: %v", err)
|
||||
}
|
||||
flat.VictimAllianceName = ""
|
||||
} else {
|
||||
flat.VictimAllianceName = name
|
||||
@@ -396,7 +410,11 @@ func flattenAttacker(ctx context.Context, db DB, killmailID int64, attacker Atta
|
||||
flog.Debug("Fetching character name")
|
||||
name, err := getCharacterName(attacker.CharacterID)
|
||||
if err != nil {
|
||||
flog.Debug("Character not found (deleted?): %v", err)
|
||||
if errors.Is(err, errNotFound) {
|
||||
flog.Debug("Character not found (deleted?)")
|
||||
} else {
|
||||
flog.Error("Failed to get character name: %v", err)
|
||||
}
|
||||
flat.CharacterName = ""
|
||||
} else {
|
||||
flat.CharacterName = name
|
||||
@@ -412,7 +430,11 @@ func flattenAttacker(ctx context.Context, db DB, killmailID int64, attacker Atta
|
||||
flog.Debug("Fetching corporation name")
|
||||
name, err := getCorporationName(attacker.CorporationID)
|
||||
if err != nil {
|
||||
flog.Debug("Corporation not found (deleted?): %v", err)
|
||||
if errors.Is(err, errNotFound) {
|
||||
flog.Debug("Corporation not found (deleted?)")
|
||||
} else {
|
||||
flog.Error("Failed to get corporation name: %v", err)
|
||||
}
|
||||
flat.CorporationName = ""
|
||||
} else {
|
||||
flat.CorporationName = name
|
||||
@@ -428,7 +450,11 @@ func flattenAttacker(ctx context.Context, db DB, killmailID int64, attacker Atta
|
||||
flog.Debug("Fetching alliance name")
|
||||
name, err := getAllianceName(attacker.AllianceID)
|
||||
if err != nil {
|
||||
flog.Debug("Alliance not found (deleted?): %v", err)
|
||||
if errors.Is(err, errNotFound) {
|
||||
flog.Debug("Alliance not found (deleted?)")
|
||||
} else {
|
||||
flog.Error("Failed to get alliance name: %v", err)
|
||||
}
|
||||
flat.AllianceName = ""
|
||||
} else {
|
||||
flat.AllianceName = name
|
||||
@@ -632,6 +658,8 @@ func flattenMarketGroupName(ctx context.Context, db DB, typeID int32) (string, e
|
||||
return marketGroup.MarketGroupName, nil
|
||||
}
|
||||
|
||||
var errNotFound = fmt.Errorf("not found")
|
||||
|
||||
func getCharacterName(characterID int64) (string, error) {
|
||||
flog := logger.Default.WithPrefix("getCharacterName").WithPrefix(fmt.Sprintf("character_%d", characterID))
|
||||
|
||||
@@ -651,11 +679,10 @@ func getCharacterName(characterID int64) (string, error) {
|
||||
cacheFile := filepath.Join(".cache", fmt.Sprintf("character_%d.json", characterID))
|
||||
char, err := cyutils.RequestCached[Character](req, cacheFile)
|
||||
if err != nil {
|
||||
// Check if it's a 404
|
||||
if err.Error() == fmt.Sprintf("character %d not found", characterID) ||
|
||||
err.Error() == fmt.Sprintf("character %d returned status 404", characterID) {
|
||||
errStr := err.Error()
|
||||
if strings.Contains(errStr, "404") || strings.Contains(errStr, "not found") {
|
||||
flog.Debug("Character not found (404)")
|
||||
return "", fmt.Errorf("character %d not found", characterID)
|
||||
return "", fmt.Errorf("character %d: %w", characterID, errNotFound)
|
||||
}
|
||||
flog.Error("Failed to get character: %v", err)
|
||||
return "", err
|
||||
@@ -684,11 +711,10 @@ func getCorporationName(corporationID int64) (string, error) {
|
||||
cacheFile := filepath.Join(".cache", fmt.Sprintf("corporation_%d.json", corporationID))
|
||||
corp, err := cyutils.RequestCached[Corporation](req, cacheFile)
|
||||
if err != nil {
|
||||
// Check if it's a 404
|
||||
if err.Error() == fmt.Sprintf("corporation %d not found", corporationID) ||
|
||||
err.Error() == fmt.Sprintf("corporation %d returned status 404", corporationID) {
|
||||
errStr := err.Error()
|
||||
if strings.Contains(errStr, "404") || strings.Contains(errStr, "not found") {
|
||||
flog.Debug("Corporation not found (404)")
|
||||
return "", fmt.Errorf("corporation %d not found", corporationID)
|
||||
return "", fmt.Errorf("corporation %d: %w", corporationID, errNotFound)
|
||||
}
|
||||
flog.Error("Failed to get corporation: %v", err)
|
||||
return "", err
|
||||
@@ -717,11 +743,10 @@ func getAllianceName(allianceID int64) (string, error) {
|
||||
cacheFile := filepath.Join(".cache", fmt.Sprintf("alliance_%d.json", allianceID))
|
||||
alliance, err := cyutils.RequestCached[Alliance](req, cacheFile)
|
||||
if err != nil {
|
||||
// Check if it's a 404
|
||||
if err.Error() == fmt.Sprintf("alliance %d not found", allianceID) ||
|
||||
err.Error() == fmt.Sprintf("alliance %d returned status 404", allianceID) {
|
||||
errStr := err.Error()
|
||||
if strings.Contains(errStr, "404") || strings.Contains(errStr, "not found") {
|
||||
flog.Debug("Alliance not found (404)")
|
||||
return "", fmt.Errorf("alliance %d not found", allianceID)
|
||||
return "", fmt.Errorf("alliance %d: %w", allianceID, errNotFound)
|
||||
}
|
||||
flog.Error("Failed to get alliance: %v", err)
|
||||
return "", err
|
||||
|
||||
Reference in New Issue
Block a user