From 1b601f21413b0c1a47dd9a882593e552ef5e4f60 Mon Sep 17 00:00:00 2001 From: Thomas Schwery Date: Tue, 7 Feb 2017 00:10:24 +0100 Subject: [PATCH] PI: Better error handling on schematics info --- main.go | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index b6caee2..d7be5b0 100644 --- a/main.go +++ b/main.go @@ -371,12 +371,16 @@ 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) - - fmt.Printf(" ✔ Factory % 5ds cycle, %s\n", - schematicInfo.CycleTime, - schematicInfo.SchematicName, - ) + 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, + ) + } } } } @@ -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 }