Skip to content

Commit

Permalink
more error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tedpearson committed Oct 22, 2024
1 parent 2f19b21 commit 9a9b909
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/app/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ func Auth(config SmartHubConfig) (string, error) {
formData.Set("password", config.Password)
authUrl := fmt.Sprintf("%s/services/oauth/auth/v2", config.ApiUrl)
parsed, err := url.Parse(config.ApiUrl)
if err != nil {
return "", err
}
authority := parsed.Hostname()
req, err := http.NewRequest("POST", authUrl, strings.NewReader(formData.Encode()))
if err != nil {
Expand Down Expand Up @@ -98,8 +101,14 @@ func FetchData(start, end time.Time, config SmartHubConfig, jwt string) (io.Read
}
pollUrl := fmt.Sprintf("%s/services/secured/utility-usage/poll", config.ApiUrl)
parsed, err := url.Parse(config.ApiUrl)
if err != nil {
return nil, err
}
authority := parsed.Hostname()
req, err := http.NewRequest("POST", pollUrl, buffer)
if err != nil {
return nil, err
}
req.Header.Set("authority", authority)
req.Header.Set("authorization", "Bearer "+jwt)
req.Header.Set("x-nisc-smarthub-username", config.Username)
Expand Down

0 comments on commit 9a9b909

Please sign in to comment.