Skip to content

Commit 73a6d5f

Browse files
authored
Merge pull request #92 from deploymenttheory/dev
Dev
2 parents ff0e917 + 34e5573 commit 73a6d5f

File tree

3 files changed

+10
-208
lines changed

3 files changed

+10
-208
lines changed

errors/http_error_handling.go

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ func (e *APIError) Error() string {
3232
}
3333

3434
// HandleAPIError handles error responses from the API, converting them into a structured error if possible.
35-
func HandleAPIError(resp *http.Response, log logger.Logger) error {
35+
func HandleAPIError(resp *http.Response, log logger.Logger) *APIError {
3636
var structuredErr StructuredError
3737
err := json.NewDecoder(resp.Body).Decode(&structuredErr)
3838
if err == nil && structuredErr.Error.Message != "" {
39-
// Using structured logging to log the structured error details
39+
// Log the structured error details
4040
log.Warn("API returned structured error",
4141
zap.String("status", resp.Status),
4242
zap.String("error_code", structuredErr.Error.Code),
@@ -49,22 +49,12 @@ func HandleAPIError(resp *http.Response, log logger.Logger) error {
4949
}
5050
}
5151

52-
var errMsg string
53-
err = json.NewDecoder(resp.Body).Decode(&errMsg)
54-
if err != nil || errMsg == "" {
55-
errMsg = fmt.Sprintf("Unexpected error with status code: %d", resp.StatusCode)
56-
// Logging with structured fields
57-
log.Error("Failed to decode API error message, using default error message",
58-
zap.String("status", resp.Status),
59-
zap.String("error_message", errMsg),
60-
)
61-
} else {
62-
// Logging non-structured error as a warning with structured fields
63-
log.Warn("API returned non-structured error",
64-
zap.String("status", resp.Status),
65-
zap.String("error_message", errMsg),
66-
)
67-
}
52+
// Default error message for non-structured responses or decode failures
53+
errMsg := fmt.Sprintf("Unexpected error with status code: %d", resp.StatusCode)
54+
log.Error("Failed to decode API error message, using default error message",
55+
zap.String("status", resp.Status),
56+
zap.String("error_message", errMsg),
57+
)
6858

6959
return &APIError{
7060
StatusCode: resp.StatusCode,

httpclient/httpclient_auth_token_management.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ func (c *Client) ValidAuthTokenCheck() (bool, error) {
2525
log.Info("Credential Match", zap.String("AuthMethod", c.AuthMethod))
2626
err := c.ObtainToken(log)
2727
if err != nil {
28-
return false, log.Error("Failed to obtain bearer token", zap.Error(err))
28+
return false, log.Error("Bearer token retrieval failed: invalid credentials. Verify accuracy.", zap.Error(err))
2929
}
3030
} else if c.AuthMethod == "oauth" {
3131
log.Info("Credential Match", zap.String("AuthMethod", c.AuthMethod))
3232
if err := c.ObtainOAuthToken(c.clientConfig.Auth); err != nil {
33-
return false, log.Error("Failed to obtain OAuth token", zap.Error(err))
33+
return false, log.Error("OAuth token retrieval failed: invalid credentials. Verify accuracy.", zap.Error(err))
3434
}
3535
} else {
3636
return false, log.Error("No valid credentials provided. Unable to obtain a token", zap.String("authMethod", c.AuthMethod))

httpclient/httpclient_client.go.back

Lines changed: 0 additions & 188 deletions
This file was deleted.

0 commit comments

Comments
 (0)