Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bounce Code Type Issue #20

Closed
travelton opened this issue Jun 28, 2014 · 11 comments · Fixed by #38
Closed

Bounce Code Type Issue #20

travelton opened this issue Jun 28, 2014 · 11 comments · Fixed by #38

Comments

@travelton
Copy link

In the Bounce struct of bounces.go, the Mailgun API returns a Code of type Int or String.

To duplicate, issue gun.GetBounces(-1, -1). If any bounces in the first page of 100 results contain a string and int in the Bounce, you'll get a type error when the json library unmarshalls the Code result to the Bounce struct.

"Error: json: cannot unmarshal string into Go value of type int"

@sam-falvo
Copy link
Contributor

I know I'm a bit late for this, but isn't this technically a bug in the Mailgun API code?

@mbanzon
Copy link
Collaborator

mbanzon commented Dec 16, 2014

I think so. The code in question is a SMTP reply code (and the RFC states that they are three digits) and should only be an integer.

The question remains if this is better to solve in this library or a fix in Mailgun API is a possibility?

@johnnylee
Copy link

Is there a workaround for this? I'm trying to figure out how to deal with bounces in Go.

@sam-falvo
Copy link
Contributor

I thought a fix for this issue was already applied. :( I'm hoping the issue was left open by accident. Stand by.

@sam-falvo
Copy link
Contributor

I'm trying to submit a PR for it now. Hang tight.

sam-falvo pushed a commit that referenced this issue May 27, 2015
Sometimes, bounce API returns status codes as strings, and other times
as integers.  This violates mailgun-go's interface conventions,
preventing us from using reflection to figure out how to automatically
decode the JSON response.

This introduces a BREAKING CHANGE to the Mailgun-go API.  However, it's
required to be enable compatbility with the existing API.

Fixes #20
@EtienneBruines
Copy link

An SMTP reply consists of a three digit number (transmitted as
three alphanumeric characters)

This means that they should be transmitted as characters (not one integer), but they should by no means be quoted (because then it wouldn't consist of three digit numbers). I feel like this should be fixed in the Mailgun API, as it's their code that's faulty, and not the Go code that should cope. Thoughts @mbanzon, @sam-falvo ?

@mbanzon
Copy link
Collaborator

mbanzon commented Jun 20, 2015

As I understood it changing this on the Mailgun side would introcude a breaking change in the API. As I see it the only option would be to have a workaround in the library (perhaps with a helper function - for those places/applications that require an actual integer response code).

@sam-falvo
Copy link
Contributor

I have a PR that has so far gone unreviewed; thinking of just committing it. It does break the API of the mailgun-go library though, because it turns that field from an integer to an interface{}. In exchange for this, though, it introduces a getter function which does return a proper integer along with an error.

See https://github.com/mailgun/mailgun-go/pull/38/files#diff-ceabd71e327239278abe0bc6cd261565R39

If someone can please review and let me know if this will meet your needs, I can just merge this myself without Mailgun's explicit OK, as this issue seems to be very low priority. Thanks! @EtienneBruines @mbanzon

@EtienneBruines
Copy link

LGTM. Perhaps the testing-function should also check on parsed JSON? (for the weird (and possibly non-existing) scenario that the type doesn't get resolved correctly? )

@mbanzon
Copy link
Collaborator

mbanzon commented Jun 23, 2015

lgtm

@sam-falvo
Copy link
Contributor

I believe that's the last test case (where we expect a syntax error). I'll commit the change, but if the test can be improved, let me know. :) Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants