Move error handling
parent
358dac794e
commit
2864ac8788
|
@ -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…
Reference in New Issue