mirror of
https://github.com/Xevion/scla-unsubscribe.git
synced 2025-12-06 11:16:20 -06:00
Fix recursive error Sprintf
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
9
main.go
9
main.go
@@ -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":
|
||||||
|
|||||||
Reference in New Issue
Block a user