Skip to content

Dev #58

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Feb 20, 2024
Merged

Dev #58

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apihandlers/jamfpro/jamfpro_api_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ func (j *JamfAPIHandler) SetBaseDomain() string {
func (j *JamfAPIHandler) ConstructAPIResourceEndpoint(instanceName string, endpointPath string, log logger.Logger) string {
urlBaseDomain := j.SetBaseDomain()
url := fmt.Sprintf("https://%s%s%s", instanceName, urlBaseDomain, endpointPath)
j.Logger.Info(fmt.Sprintf("Constructed %s API resource endpoint URL", APIName), zap.String("URL", url))
j.Logger.Debug(fmt.Sprintf("Constructed %s API resource endpoint URL", APIName), zap.String("URL", url))
return url
}

// ConstructAPIAuthEndpoint constructs the full URL for a Jamf API auth endpoint path and logs the URL.
func (j *JamfAPIHandler) ConstructAPIAuthEndpoint(instanceName string, endpointPath string, log logger.Logger) string {
urlBaseDomain := j.SetBaseDomain()
url := fmt.Sprintf("https://%s%s%s", instanceName, urlBaseDomain, endpointPath)
j.Logger.Info(fmt.Sprintf("Constructed %s API authentication URL", APIName), zap.String("URL", url))
j.Logger.Debug(fmt.Sprintf("Constructed %s API authentication URL", APIName), zap.String("URL", url))
return url
}
6 changes: 5 additions & 1 deletion errors/http_error_handling.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func HandleAPIError(resp *http.Response, log logger.Logger) error {
if err != nil || errMsg == "" {
errMsg = fmt.Sprintf("Unexpected error with status code: %d", resp.StatusCode)
// Logging with structured fields
log.Warn("Failed to decode API error message, using default error message",
log.Error("Failed to decode API error message, using default error message",
zap.String("status", resp.Status),
zap.String("error_message", errMsg),
)
Expand Down Expand Up @@ -163,6 +163,10 @@ func IsNonRetryableStatusCode(resp *http.Response) bool {

// IsRateLimitError checks if the provided response indicates a rate limit error.
func IsRateLimitError(resp *http.Response) bool {
if resp == nil {
// If the response is nil, it cannot be a rate limit error.
return false
}
return resp.StatusCode == http.StatusTooManyRequests
}

Expand Down
2 changes: 1 addition & 1 deletion httpclient/httpclient_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func (c *Client) executeHTTPRequest(req *http.Request, log logger.Logger, method
}

// Log the response status code for successful requests
log.Info("Request sent successfully",
log.Debug("Request sent successfully",
zap.String("method", method),
zap.String("endpoint", endpoint),
zap.Int("status_code", resp.StatusCode),
Expand Down