Fix recursive error Sprintf

This commit is contained in:
2023-12-26 15:10:06 -06:00
parent 2a5789e758
commit dfe9de53a7
2 changed files with 8 additions and 5 deletions

View File

@@ -11,11 +11,11 @@ type UnsubscribeUnexpectedError struct {
} }
func (e ChecksumMissingError) Error() string { func (e ChecksumMissingError) Error() string {
return fmt.Sprintf("checksum missing: %x", e) return fmt.Sprintf("checksum missing: %x", []byte(e[:]))
} }
func (e ChecksumInvalidError) Error() string { func (e ChecksumInvalidError) Error() string {
return fmt.Sprintf("checksum invalid: %x", e) return fmt.Sprintf("checksum invalid: %x", []byte(e[:]))
} }
func (e UnsubscribeRejectedError) Error() string { func (e UnsubscribeRejectedError) Error() string {

View File

@@ -114,14 +114,17 @@ func Unsubscribe(email string) (*ConfirmationResponse, error) {
if response.StatusCode != 200 { if response.StatusCode != 200 {
// If JSON returned, parse the message for the error // If JSON returned, parse the message for the error
contentType := response.Header.Get("Content-Type") contentType := response.Header.Get("Content-Type")
if strings.Contains(contentType, "application/json") { if !strings.Contains(contentType, "application/json") {
return nil, UnsubscribeUnexpectedError{Message: string(body), Code: response.StatusCode} return nil, UnsubscribeUnexpectedError{Message: string(body), Code: response.StatusCode}
} }
// Parse the JSON // Parse the JSON
var errorResponse ErrorResponse var errorResponse ErrorResponse
json.Unmarshal(body, &errorResponse) err := json.Unmarshal(body, &errorResponse)
log.Debug().Interface("errorResponse", errorResponse).Msg("Error Response") if err != nil {
log.Error().Err(err).Msg("Error parsing error response")
return nil, UnsubscribeUnexpectedError{Message: string(body), Code: response.StatusCode}
}
switch errorResponse.Message { switch errorResponse.Message {
case "checksum invalid": case "checksum invalid":