-
Notifications
You must be signed in to change notification settings - Fork 19
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
BatchAPI::execute has inconsistent return values #69
Comments
Hey @jlesueur, after thinking on this I'm not sure I agree. The boiler plate is useful in that you can catch errors that aren't related to the content of the batch request and deal with them appropriately. What are you doing to run into this case? |
We sent a batch larger than 100 emails. And I agree, the proposed fix, isn't necessarily best. Not sure what your standard/opinion is on exceptions, but this seems like the proper place to throw an exception. When executing a batch, the standard return is a set of responses for each item in the batch. If you can't return that, it's an exceptional case. With an exception, it just becomes more explicit:
instead of an |
Yeah, I can see that being a better pattern; however, the client currently does something similar with non-batch API calls. There's a higher level discussion that needs to be had about how a user interacts with failed API calls for all methods. What I'd rather see is all methods throw an exception for any request that doesn't respond with a 200. What do you think @jlesueur ? |
For single api calls, an exception (with specific types used for different kinds of errors) for any kind of failure is a nice touch. Batch calls need some special care, since there are two levels of success/failure:
So an exception when the batch call itself fails is very appropriate. An exception if any item in the batch fails might make sense, but would have to include some way of discovering which ones succeeded and which failed. I think I would kind of lean away from an exception if any item in the batch failed, and instead return an object that included the total number attempted, and the number that succeeded, and then the array of responses for each item. |
Client version
v3.0.0
Expected behaviour
When execute is called, it should always return an array of responses (a single output type).
should output succeeded in all cases
Actual behaviour
outputs failed if the batch was too large, or authentication failed, or any failure that's not specific to one of the emails in the batch.
The reason for requesting a change is that the current behavior requires boilerplate whenever calling execute():
Simplest "fix" would be to change this line: https://github.com/sendwithus/sendwithus_php/blob/master/lib/API.php#L782 to return the single error as an array. That way, a consumer can always depend on getting back an array.
The text was updated successfully, but these errors were encountered: