Skip to content

Commit 9a9b909

Browse files
committed
more error handling
1 parent 2f19b21 commit 9a9b909

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

internal/app/api.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ func Auth(config SmartHubConfig) (string, error) {
2626
formData.Set("password", config.Password)
2727
authUrl := fmt.Sprintf("%s/services/oauth/auth/v2", config.ApiUrl)
2828
parsed, err := url.Parse(config.ApiUrl)
29+
if err != nil {
30+
return "", err
31+
}
2932
authority := parsed.Hostname()
3033
req, err := http.NewRequest("POST", authUrl, strings.NewReader(formData.Encode()))
3134
if err != nil {
@@ -98,8 +101,14 @@ func FetchData(start, end time.Time, config SmartHubConfig, jwt string) (io.Read
98101
}
99102
pollUrl := fmt.Sprintf("%s/services/secured/utility-usage/poll", config.ApiUrl)
100103
parsed, err := url.Parse(config.ApiUrl)
104+
if err != nil {
105+
return nil, err
106+
}
101107
authority := parsed.Hostname()
102108
req, err := http.NewRequest("POST", pollUrl, buffer)
109+
if err != nil {
110+
return nil, err
111+
}
103112
req.Header.Set("authority", authority)
104113
req.Header.Set("authorization", "Bearer "+jwt)
105114
req.Header.Set("x-nisc-smarthub-username", config.Username)

0 commit comments

Comments
 (0)