From 48827804e60076fc770845154044b29395f098e7 Mon Sep 17 00:00:00 2001 From: Peiman Jafari <18074432+peimanja@users.noreply.github.com> Date: Wed, 24 Jun 2020 11:28:16 -0700 Subject: [PATCH] Make API errors an interface (#41) --- artifactory/utils.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/artifactory/utils.go b/artifactory/utils.go index eea3274..87060f4 100644 --- a/artifactory/utils.go +++ b/artifactory/utils.go @@ -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 @@ -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, } } @@ -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, } }