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

Add support for AdvanceErrorHandling when sending a message #89

Merged

Conversation

mariuskiessling
Copy link
Contributor

Background

The API documentation of Mailjet's API v3.1 specifies a parameter called AdvanceErrorHandling (not a typo, this is actually what it is called) for its send action. If this option is set, the server will perform additional validations on the request before it marks a transaction as successful. This is e.g. required to catch emails that should be sent with a unauthorised sender email address. Without this flag, the server would accept a request with an unauthorised sender email address and return a payload to the client that contains message information for a resource that was not actually dispatched.

Changes

  • The MessagesV31 struct now supports the AdvanceErrorHandling field
  • The unit test for the SendMailV31 method has been re-written into a table test. The test now also validates that the client transmits the correct payload and sets the right encoding and authorization headers. More crucially, the test now also validates that the client can deal with both successful as well as non-successful responses from the server. This should have been done in the first place as there is specific error handling code for different HTTP status codes. If the client implementation was messed up, this could lead to error decoding problems because different kind of errors are decoded into different structs.

Open Questions

Whenever the server returns an error with the HTTP status code 400 or 403, the APIErrorDetailsV31 struct is chosen to hold the decoded error contents. The server however returns two additional properties (ErrorIdentifier and ErorrCode) that are currently not defined in the APIErrorDetailsV31 struct. In addition, the API documentation that is linked here under the AdvanceErrorHandling parameter description does not seem to exist. Hence, I could not find any formal definition of the error's structure.

  • Could you check with your backend engineers how this error's structure is currently defined?
  • In addition, is the ErrorClass still a valid response field for an error? The API does not seem to return it for any faulty requests. If not, I will mark it as deprecated. We should not remove it to not break backwards-compatibility within the major module version.

@mariuskiessling
Copy link
Contributor Author

In addition, I was wondering why the go.sum file is not checked in. Is there any good reason for this?

@mariuskiessling
Copy link
Contributor Author

@tsidei Could you give me quick response about the two open questions above so I can finalise the PR?

Copy link
Collaborator

@tsidei tsidei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, apologies for late response

As for error fields, we should add the two missing ones (ErrorCode and ErrorIdentifier), ErrorClass is not used so yeah, let's mark it as deprecated with a comment.

I think go.sum wasn't checked in because the go tool doesn't generate it since there are no external dependencies. You can still create it, but it will be empty.

Overall the PR looks good, let's add the missing fields and it should be good to go. Sorry again for the long waiting. Tests also look better now, thanks!

Comment on lines 521 to 523
// TODO: Missing ErrorIdentifier in struct
// TODO: Missing ErorrCode in struct, but ErrorClass exists
// -> Correct format not defined in API docs
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, we should add those missing fields. Please add them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added them. Thanks!

@mariuskiessling mariuskiessling force-pushed the advanced-error-handling-support branch from f2b64ab to a051626 Compare July 5, 2022 09:55
In addition to the support of the new field, this commit improves the
testing of the SendMailV31 method. The tests now validate that the
request payload matches the passed input and that encoding and
authorization information are present. The APIErrorDetailsV31 struct now
also supports the ErrorCode and ErrorIdentifier fields. The ErrorClass
field of that struct is now deprecated.

Signed-off-by: Marius Kießling <marius.kiessling@metro.digital>
@mariuskiessling mariuskiessling force-pushed the advanced-error-handling-support branch from a051626 to 0a7dc9e Compare July 5, 2022 10:03
@mariuskiessling mariuskiessling marked this pull request as ready for review July 5, 2022 10:04
@mariuskiessling
Copy link
Contributor Author

mariuskiessling commented Jul 5, 2022

Hi, apologies for late response

As for error fields, we should add the two missing ones (ErrorCode and ErrorIdentifier), ErrorClass is not used so yeah, let's mark it as deprecated with a comment.

I think go.sum wasn't checked in because the go tool doesn't generate it since there are no external dependencies. You can still create it, but it will be empty.

Overall the PR looks good, let's add the missing fields and it should be good to go. Sorry again for the long waiting. Tests also look better now, thanks!

Thanks for the feedback! I adapted your notes by adding the two new fields and marking the ErrorClass as deprecated. Regarding the go.mod file: Go generates it with the normal header

module github.com/mailjet/mailjet-apiv3-go/v3

go 1.13

but no dependencies listed as the module doesn't have any. This is why I was asking about it. To the best of my knowledge, it is also common to check the file in even if no dependencies are used. But this shouldn't stop us from going ahead with this PR.

I prepared my final commit and rebased onto master. You should now be able to finally review the code. Cheers!

@tsidei
Copy link
Collaborator

tsidei commented Jul 5, 2022

yes, the go.mod file is generated fine and it is in the repo already, I was talking about go.sum, that one wasn't generated for me and I thought it's because no external dependencies.
Anyway, I'm okay with including an empty one to follow the common practice. Please include it here or let me know and it'll be done separately.

The rest of the PR looks good! Thanks for the contribution.

@mariuskiessling
Copy link
Contributor Author

Ah sorry, my bad. I don't have any strong feelings about the topic. Just go ahead without including the go.sum file.

@tsidei tsidei merged commit 5ddebe4 into mailjet:master Jul 6, 2022
@tsidei
Copy link
Collaborator

tsidei commented Jul 6, 2022

released in 4.0.0. Thank you!

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

Successfully merging this pull request may close these issues.

None yet

2 participants