Handle additional possible errors

This commit is contained in:
Thomas Schwery 2017-03-25 14:33:38 +00:00
parent f51c48d68b
commit 4f26133a38

39
main.go
View file

@ -193,7 +193,11 @@ func getCharacterInfo(client *http.Client) (*Character, error) {
}
defer response.Body.Close()
contents, _ := ioutil.ReadAll(response.Body)
contents, errRead := ioutil.ReadAll(response.Body)
if errRead != nil {
log.Printf("Read error: %s\n", errRead)
return nil, errRead
}
var m Character
errJSON := json.Unmarshal(contents, &m)
@ -371,7 +375,11 @@ func printClonesInformation(swaggerclient *ESI.App, m *Character) string {
clones := cloresponse.Payload.JumpClones
for _, clone := range clones {
sInfo, _ := getStructureStationInfo(swaggerclient, clone.LocationType, clone.LocationID)
sInfo, sErr := getStructureStationInfo(swaggerclient, clone.LocationType, clone.LocationID)
if sErr != nil {
fmt.Printf("Error on structure information read on structure %s\n", clone.LocationID)
log.Fatalf("Got error on getStructureStationInfo: %T %s", sErr, sErr)
}
content = content + fmt.Sprintf(" %s, %s, %s\n ",
sInfo.Name,
@ -639,7 +647,11 @@ func getPlanetInformation(swaggerclient *ESI.App, planetID int32) planetInformat
pcallParams := ESIUniverse.NewGetUniversePlanetsPlanetIDParams()
pcallParams.WithPlanetID(planetID)
pesiresponse, _ := swaggerclient.Universe.GetUniversePlanetsPlanetID(pcallParams)
pesiresponse, pesierror := swaggerclient.Universe.GetUniversePlanetsPlanetID(pcallParams)
if pesierror != nil {
log.Printf("Error on GetUniversePlanetsPlanetID on planet: %v\n", planetID)
log.Printf("Error on GetUniversePlanetsPlanetID: %s\n", pesierror)
}
planetESIInfo := pesiresponse.Payload
@ -680,7 +692,12 @@ func getSolarSystemInformation(swaggerclient *ESI.App, solarSystemID int32) sola
scallParams := ESIUniverse.NewGetUniverseSystemsSystemIDParams()
scallParams.WithSystemID(solarSystemID)
sesiresponse, _ := swaggerclient.Universe.GetUniverseSystemsSystemID(scallParams)
sesiresponse, sesierror := swaggerclient.Universe.GetUniverseSystemsSystemID(scallParams)
if sesierror != nil {
log.Printf("Error on GetUniverseSystemsSystemID on system: %v\n", solarSystemID)
log.Printf("Error on GetUniverseSystemsSystemID: %s\n", sesierror)
}
solarSystemESIInfo := sesiresponse.Payload
var ssInfo solarSystemInfo
@ -690,7 +707,12 @@ func getSolarSystemInformation(swaggerclient *ESI.App, solarSystemID int32) sola
ccallParams := ESIUniverse.NewGetUniverseConstellationsConstellationIDParams()
ccallParams.WithConstellationID(ssInfo.ConstellationID)
cesiresponse, _ := swaggerclient.Universe.GetUniverseConstellationsConstellationID(ccallParams)
cesiresponse, cesierror := swaggerclient.Universe.GetUniverseConstellationsConstellationID(ccallParams)
if cesierror != nil {
log.Printf("Error on GetUniverseConstellationsConstellationID on constellation: %v\n", ssInfo.ConstellationID)
log.Printf("Error on GetUniverseConstellationsConstellationID: %s\n", cesierror)
}
constellationESIInfo := cesiresponse.Payload
ssInfo.ConstellationName = *constellationESIInfo.Name
@ -699,7 +721,12 @@ func getSolarSystemInformation(swaggerclient *ESI.App, solarSystemID int32) sola
rcallParams := ESIUniverse.NewGetUniverseRegionsRegionIDParams()
rcallParams.WithRegionID(ssInfo.RegionID)
resiresponse, _ := swaggerclient.Universe.GetUniverseRegionsRegionID(rcallParams)
resiresponse, resierror := swaggerclient.Universe.GetUniverseRegionsRegionID(rcallParams)
if resierror != nil {
log.Printf("Error on GetUniverseRegionsRegionID on region: %v\n", ssInfo.RegionID)
log.Printf("Error on GetUniverseRegionsRegionID: %s\n", cesierror)
}
regionESIInfo := resiresponse.Payload
ssInfo.RegionName = *regionESIInfo.Name