Skip to content

Commit

Permalink
removed unnecessary comments
Browse files Browse the repository at this point in the history
  • Loading branch information
thejoeker12 committed Jul 9, 2024
1 parent aaf9acf commit c8c9707
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 10 deletions.
4 changes: 0 additions & 4 deletions response/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,15 @@ type APIError struct {

// Error returns a string representation of the APIError, making it compatible with the error interface.
func (e *APIError) Error() string {
// Attempt to marshal the APIError instance into a JSON string.
data, err := json.Marshal(e)
if err == nil {
return string(data)
}

// Use the standard HTTP status text as the error message if 'Message' field is empty.
if e.Message == "" {
e.Message = http.StatusText(e.StatusCode)
}

// Fallback to a simpler error message format if JSON marshaling fails.
return fmt.Sprintf("API Error: StatusCode=%d, Message=%s", e.StatusCode, e.Message)
}

Expand Down Expand Up @@ -179,7 +176,6 @@ func parseHTMLResponse(bodyBytes []byte, apiError *APIError) {

parse(doc)

// Concatenate all accumulated messages and links with a separator.
if len(messages) > 0 {
apiError.Message = strings.Join(messages, "; ")
} else {
Expand Down
4 changes: 2 additions & 2 deletions response/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import "strings"
// parseHeader generalizes the parsing of headers like Content-Type and Content-Disposition.
// It extracts the main value (e.g., MIME type for Content-Type) and any parameters (like charset).
func parseHeader(header string) (string, map[string]string) {
parts := strings.SplitN(header, ";", 2) // Split into main value and parameters
parts := strings.SplitN(header, ";", 2)
mainValue := strings.TrimSpace(parts[0])

params := make(map[string]string)
if len(parts) > 1 { // Check if there are parameters
if len(parts) > 1 {
for _, part := range strings.Split(parts[1], ";") {
kv := strings.SplitN(part, "=", 2)
if len(kv) == 2 {
Expand Down
4 changes: 0 additions & 4 deletions response/success.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,16 @@ func HandleAPISuccessResponse(resp *http.Response, out interface{}, sugar *zap.S
return handleDeleteRequest(resp, sugar)
}

// Read the response body into a buffer
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
sugar.Error("Failed to read response body", zap.Error(err))
return err
}

// After reading, reset resp.Body so it can be read again.
sugar.Debug("HTTP Response Headers", zap.Any("Headers", resp.Header))
sugar.Debug("Raw HTTP Response", zap.String("Body", string(bodyBytes)))

// Use the buffer to create a new io.Reader for unmarshalling
bodyReader := bytes.NewReader(bodyBytes)

mimeType, _ := parseHeader(resp.Header.Get("Content-Type"))
contentDisposition := resp.Header.Get("Content-Disposition")

Expand Down

0 comments on commit c8c9707

Please sign in to comment.