Move error handling

master
Elis Hirwing 5 years ago
parent 358dac794e
commit 2864ac8788
Signed by: etu
GPG Key ID: D57EFA625C9A925F
  1. 16
      src/statusscreen/SL.go

@ -52,7 +52,11 @@ func (sl *SL) GetOutput() string {
"Expcted",
})
sldata := sl.getTimeTable()
sldata, err := sl.getTimeTable()
if err != nil {
log.Fatal(err)
}
for _, v := range sldata.ResponseData.Metros {
table.Append([]string{
@ -69,7 +73,7 @@ func (sl *SL) GetOutput() string {
return b.String()
}
func (sl *SL) getTimeTable() SLResponse {
func (sl *SL) getTimeTable() (SLResponse, error) {
parsedResponse := SLResponse{}
// Construct URL with APIKey and Site
@ -83,22 +87,22 @@ func (sl *SL) getTimeTable() SLResponse {
// Do request
resp, err := client.Get(url)
if err != nil {
log.Fatal(err)
return parsedResponse, err
}
// Read response
body, readErr := ioutil.ReadAll(resp.Body)
if readErr != nil {
log.Fatal(readErr)
return parsedResponse, readErr
}
// Parse response from SL
parseErr := json.Unmarshal(body, &parsedResponse)
if parseErr != nil {
log.Fatal(parseErr)
return parsedResponse, parseErr
}
return parsedResponse
return parsedResponse, nil
}
func (sl *SL) formatDisplayTime(expected string) string {

Loading…
Cancel
Save