mirror of
https://github.com/Xevion/scla-unsubscribe.git
synced 2025-12-06 01:16:15 -06:00
Fix recursive error Sprintf
This commit is contained in:
@@ -11,11 +11,11 @@ type UnsubscribeUnexpectedError struct {
|
||||
}
|
||||
|
||||
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 {
|
||||
return fmt.Sprintf("checksum invalid: %x", e)
|
||||
return fmt.Sprintf("checksum invalid: %x", []byte(e[:]))
|
||||
}
|
||||
|
||||
func (e UnsubscribeRejectedError) Error() string {
|
||||
|
||||
9
main.go
9
main.go
@@ -114,14 +114,17 @@ func Unsubscribe(email string) (*ConfirmationResponse, error) {
|
||||
if response.StatusCode != 200 {
|
||||
// If JSON returned, parse the message for the error
|
||||
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}
|
||||
}
|
||||
|
||||
// Parse the JSON
|
||||
var errorResponse ErrorResponse
|
||||
json.Unmarshal(body, &errorResponse)
|
||||
log.Debug().Interface("errorResponse", errorResponse).Msg("Error Response")
|
||||
err := json.Unmarshal(body, &errorResponse)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Error parsing error response")
|
||||
return nil, UnsubscribeUnexpectedError{Message: string(body), Code: response.StatusCode}
|
||||
}
|
||||
|
||||
switch errorResponse.Message {
|
||||
case "checksum invalid":
|
||||
|
||||
Reference in New Issue
Block a user