Skip to content

Commit 06ddcb5

Browse files
authored
Merge pull request #137 from deploymenttheory/dev
Code clean up
2 parents aa0b9e0 + ba69896 commit 06ddcb5

File tree

8 files changed

+38
-566
lines changed

8 files changed

+38
-566
lines changed

apiintegrations/apihandler/apihandler.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ type APIHandler interface {
1818
MarshalRequest(body interface{}, method string, endpoint string, log logger.Logger) ([]byte, error)
1919
MarshalMultipartRequest(fields map[string]string, files map[string]string, log logger.Logger) ([]byte, string, error)
2020
HandleAPISuccessResponse(resp *http.Response, out interface{}, log logger.Logger) error
21-
//HandleAPIErrorResponse(resp *http.Response, out interface{}, log logger.Logger) error
2221
GetContentTypeHeader(method string, log logger.Logger) string
2322
GetAcceptHeader() string
2423
GetDefaultBaseDomain() string

apiintegrations/jamfpro/jamfpro_api_error_messages.go

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

apiintegrations/jamfpro/jamfpro_api_response.go

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -93,72 +93,6 @@ func (j *JamfAPIHandler) handleBinaryData(contentType, contentDisposition string
9393
return nil // If not binary data, no action needed
9494
}
9595

96-
// func (j *JamfAPIHandler) HandleAPIErrorResponse(resp *http.Response, out interface{}, log logger.Logger) error {
97-
// // Read the response body
98-
// bodyBytes, err := j.readResponseBody(resp)
99-
// if err != nil {
100-
// return err
101-
// }
102-
103-
// // Convert bodyBytes to a string to represent the raw response body
104-
// rawResponse := string(bodyBytes)
105-
106-
// // Log the raw response details for debugging
107-
// j.logResponseDetails(resp, bodyBytes)
108-
109-
// // Get the content type from the response headers
110-
// contentType := resp.Header.Get("Content-Type")
111-
112-
// // Handle known error content types (e.g., JSON, HTML)
113-
// if strings.Contains(contentType, "application/json") {
114-
// return j.handleErrorJSONResponse(bodyBytes, resp.StatusCode, rawResponse)
115-
// } else if strings.Contains(contentType, "text/html") {
116-
// return j.handleErrorHTMLResponse(bodyBytes, resp.StatusCode)
117-
// }
118-
119-
// // Generic error handling for unknown content types
120-
// j.Logger.Error("Received non-success status code without detailed error response",
121-
// zap.Int("status_code", resp.StatusCode),
122-
// zap.String("raw_response", rawResponse),
123-
// )
124-
// return fmt.Errorf("received non-success status code: %d, raw response: %s", resp.StatusCode, rawResponse)
125-
// }
126-
127-
// handleErrorHTMLResponse handles error responses with HTML content by extracting and logging the error message.
128-
// func (j *JamfAPIHandler) handleErrorHTMLResponse(bodyBytes []byte, statusCode int) error {
129-
// // Extract the error message from the HTML content
130-
// htmlErrorMessage := ExtractErrorMessageFromHTML(string(bodyBytes))
131-
// // Log the error message along with the status code
132-
// j.Logger.Error("Received HTML error content",
133-
// zap.String("error_message", htmlErrorMessage),
134-
// zap.Int("status_code", statusCode),
135-
// )
136-
// // Return an error with the extracted message
137-
// return fmt.Errorf("received HTML error content: %s", htmlErrorMessage)
138-
// }
139-
140-
// handleErrorJSONResponse handles error responses with JSON content by parsing the error message and logging it.
141-
// func (j *JamfAPIHandler) handleErrorJSONResponse(bodyBytes []byte, statusCode int, rawResponse string) error {
142-
// // Parse the JSON error response to extract the error description
143-
// description, err := ParseJSONErrorResponse(bodyBytes)
144-
// if err != nil {
145-
// // Log the parsing error
146-
// j.Logger.Error("Failed to parse JSON error response",
147-
// zap.Error(err),
148-
// zap.Int("status_code", statusCode),
149-
// zap.String("raw_response", rawResponse), // Include raw response in the log
150-
// )
151-
// return fmt.Errorf("failed to parse JSON error response: %v, raw response: %s", err, rawResponse)
152-
// }
153-
// // Log the error description along with the status code and raw response
154-
// j.Logger.Error("Received non-success status code with JSON response",
155-
// zap.Int("status_code", statusCode),
156-
// zap.String("error_description", description),
157-
// zap.String("raw_response", rawResponse), // Include raw response in the log
158-
// )
159-
// return fmt.Errorf("received non-success status code with JSON response: %s, raw response: %s", description, rawResponse)
160-
// }
161-
16296
// unmarshalResponse unmarshals the response body into the provided output structure based on the content type (JSON or XML).
16397
func (j *JamfAPIHandler) unmarshalResponse(contentType string, bodyBytes []byte, out interface{}) error {
16498
// Determine the content type and unmarshal accordingly

apiintegrations/msgraph/msgraph_api_error_messages.go

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

apiintegrations/msgraph/msgraph_api_response.go

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// msgraph_api_response.go
1+
// jamfpro_api_handler.go
22
package msgraph
33

44
import (
@@ -41,37 +41,6 @@ func (g *GraphAPIHandler) HandleAPISuccessResponse(resp *http.Response, out inte
4141
return g.unmarshalResponse(contentType, bodyBytes, out)
4242
}
4343

44-
func (g *GraphAPIHandler) HandleAPIErrorResponse(resp *http.Response, out interface{}, log logger.Logger) error {
45-
// Read the response body
46-
bodyBytes, err := g.readResponseBody(resp)
47-
if err != nil {
48-
return err
49-
}
50-
51-
// Convert bodyBytes to a string to represent the raw response body
52-
rawResponse := string(bodyBytes)
53-
54-
// Log the raw response details for debugging
55-
g.logResponseDetails(resp, bodyBytes)
56-
57-
// Get the content type from the response headers
58-
contentType := resp.Header.Get("Content-Type")
59-
60-
// Handle known error content types (e.g., JSON, HTML)
61-
if strings.Contains(contentType, "application/json") {
62-
return g.handleErrorJSONResponse(bodyBytes, resp.StatusCode, rawResponse)
63-
} else if strings.Contains(contentType, "text/html") {
64-
return g.handleErrorHTMLResponse(bodyBytes, resp.StatusCode)
65-
}
66-
67-
// Generic error handling for unknown content types
68-
g.Logger.Error("Received non-success status code without detailed error response",
69-
zap.Int("status_code", resp.StatusCode),
70-
zap.String("raw_response", rawResponse),
71-
)
72-
return fmt.Errorf("received non-success status code: %d, raw response: %s", resp.StatusCode, rawResponse)
73-
}
74-
7544
// handleDeleteRequest handles the special case for DELETE requests, where a successful response might not contain a body.
7645
func (g *GraphAPIHandler) handleDeleteRequest(resp *http.Response) error {
7746
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
@@ -124,41 +93,6 @@ func (g *GraphAPIHandler) handleBinaryData(contentType, contentDisposition strin
12493
return nil // If not binary data, no action needed
12594
}
12695

127-
// handleErrorHTMLResponse handles error responses with HTML content by extracting and logging the error message.
128-
func (g *GraphAPIHandler) handleErrorHTMLResponse(bodyBytes []byte, statusCode int) error {
129-
// Extract the error message from the HTML content
130-
htmlErrorMessage := ExtractErrorMessageFromHTML(string(bodyBytes))
131-
// Log the error message along with the status code
132-
g.Logger.Error("Received HTML error content",
133-
zap.String("error_message", htmlErrorMessage),
134-
zap.Int("status_code", statusCode),
135-
)
136-
// Return an error with the extracted message
137-
return fmt.Errorf("received HTML error content: %s", htmlErrorMessage)
138-
}
139-
140-
// handleErrorJSONResponse handles error responses with JSON content by parsing the error message and logging it.
141-
func (g *GraphAPIHandler) handleErrorJSONResponse(bodyBytes []byte, statusCode int, rawResponse string) error {
142-
// Parse the JSON error response to extract the error description
143-
description, err := ParseJSONErrorResponse(bodyBytes)
144-
if err != nil {
145-
// Log the parsing error
146-
g.Logger.Error("Failed to parse JSON error response",
147-
zap.Error(err),
148-
zap.Int("status_code", statusCode),
149-
zap.String("raw_response", rawResponse), // Include raw response in the log
150-
)
151-
return fmt.Errorf("failed to parse JSON error response: %v, raw response: %s", err, rawResponse)
152-
}
153-
// Log the error description along with the status code and raw response
154-
g.Logger.Error("Received non-success status code with JSON response",
155-
zap.Int("status_code", statusCode),
156-
zap.String("error_description", description),
157-
zap.String("raw_response", rawResponse), // Include raw response in the log
158-
)
159-
return fmt.Errorf("received non-success status code with JSON response: %s, raw response: %s", description, rawResponse)
160-
}
161-
16296
// unmarshalResponse unmarshals the response body into the provided output structure based on the content type (JSON or XML).
16397
func (g *GraphAPIHandler) unmarshalResponse(contentType string, bodyBytes []byte, out interface{}) error {
16498
// Determine the content type and unmarshal accordingly

0 commit comments

Comments
 (0)