Browse Source

Move error handling

master
Elis Hirwing 2 years ago
parent
commit
2864ac8788
Signed by: etu <elis@hirwing.se> GPG Key ID: D57EFA625C9A925F
1 changed files with 10 additions and 6 deletions
  1. +10
    -6
      src/statusscreen/SL.go

+ 10
- 6
src/statusscreen/SL.go View File

@@ -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