Skip to content

Commit

Permalink
Make API errors an interface (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
peimanja authored Jun 24, 2020
1 parent b8032c7 commit 4882780
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions artifactory/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import (

// APIErrors represents Artifactory API Error response
type APIErrors struct {
Errors []struct {
Status int `json:"status,omitempty"`
Message string `json:"message,omitempty"`
} `json:"errors,omitempty"`
Errors interface{}
}

// FetchHTTP is a wrapper function for making all Get API calls
Expand Down Expand Up @@ -50,11 +47,10 @@ func (c *Client) FetchHTTP(path string) ([]byte, error) {
endpoint: fullPath,
}
}
level.Error(c.logger).Log("msg", "There was an error making API call", "endpoint", fullPath, "err", apiErrors.Errors[0].Message, "status", apiErrors.Errors[0].Status)
level.Error(c.logger).Log("msg", "There was an error making API call", "endpoint", fullPath, "err", fmt.Sprintf("%v", apiErrors.Errors), "status")
return nil, &APIError{
message: apiErrors.Errors[0].Message,
message: fmt.Sprintf("%v", apiErrors.Errors),
endpoint: fullPath,
status: apiErrors.Errors[0].Status,
}
}

Expand Down Expand Up @@ -98,11 +94,10 @@ func (c *Client) QueryAQL(query []byte) ([]byte, error) {
endpoint: fullPath,
}
}
level.Error(c.logger).Log("msg", "There was an error making API call", "endpoint", fullPath, "err", apiErrors.Errors[0].Message, "status", apiErrors.Errors[0].Status)
level.Error(c.logger).Log("msg", "There was an error making API call", "endpoint", fullPath, "err", fmt.Sprintf("%v", apiErrors.Errors), "status")
return nil, &APIError{
message: apiErrors.Errors[0].Message,
message: fmt.Sprintf("%v", apiErrors.Errors),
endpoint: fullPath,
status: apiErrors.Errors[0].Status,
}
}

Expand Down

0 comments on commit 4882780

Please sign in to comment.