PI: Better error handling on schematics info

This commit is contained in:
Thomas Schwery 2017-02-07 00:10:24 +01:00
parent 3a4411a49a
commit 1b601f2141

19
main.go
View file

@ -371,8 +371,11 @@ func printCharacterPlanets(swaggerclient *ESI.App, m *Character) {
} else if pin.SchematicID != 0 {
// Get the schematic from ESI and cache it
schematicInfo := getSchematicsInformation(swaggerclient, pin.SchematicID)
schematicInfo, serr := getSchematicsInformation(swaggerclient, pin.SchematicID)
if serr != nil {
log.Printf("Error on getSchematicsInformation: %T, %s\n", serr, serr)
fmt.Printf(" ✔ Factory ????? cycle, ?????\n")
} else {
fmt.Printf(" ✔ Factory % 5ds cycle, %s\n",
schematicInfo.CycleTime,
schematicInfo.SchematicName,
@ -380,6 +383,7 @@ func printCharacterPlanets(swaggerclient *ESI.App, m *Character) {
}
}
}
}
}
func getUniverseNames(swaggerclient *ESI.App, itemIds *[]int32) map[int32]string {
@ -459,7 +463,7 @@ type SchematicInfo struct {
SchematicName string
}
func getSchematicsInformation(swaggerclient *ESI.App, schematicID int32) SchematicInfo {
func getSchematicsInformation(swaggerclient *ESI.App, schematicID int32) (*SchematicInfo, error) {
schematicName := getCachedData(fmt.Sprintf("%d.name", schematicID))
schematicCycle := getCachedData(fmt.Sprintf("%d.cycle", schematicID))
@ -468,7 +472,10 @@ func getSchematicsInformation(swaggerclient *ESI.App, schematicID int32) Schemat
scallParams := ESIPlanetaryInteraction.NewGetUniverseSchematicsSchematicIDParams()
scallParams.WithSchematicID(schematicID)
sesiresponse, _ := swaggerclient.PlanetaryInteraction.GetUniverseSchematicsSchematicID(scallParams)
sesiresponse, sesierr := swaggerclient.PlanetaryInteraction.GetUniverseSchematicsSchematicID(scallParams)
if sesierr != nil {
return nil, sesierr
}
schematicsESIInfo := sesiresponse.Payload
@ -479,14 +486,14 @@ func getSchematicsInformation(swaggerclient *ESI.App, schematicID int32) Schemat
putCacheData(fmt.Sprintf("%d.name", schematicID), schematicInfo.SchematicName)
putCacheData(fmt.Sprintf("%d.cycle", schematicID), fmt.Sprintf("%d", schematicInfo.CycleTime))
return schematicInfo
return &schematicInfo, nil
}
var schematicInfo SchematicInfo
pCycleTime, _ := strconv.ParseInt(schematicCycle, 10, 32)
schematicInfo.CycleTime = int32(pCycleTime)
schematicInfo.SchematicName = schematicName
return schematicInfo
return &schematicInfo, nil
}