Skip to content

BatchAPI::execute has inconsistent return values #69

@jlesueur

Description

@jlesueur

Client version

v3.0.0

Expected behaviour

When execute is called, it should always return an array of responses (a single output type).

$batch = $api->start_batch();
$batch->send();
$responses = $batch->execute();
if (is_array($responses)) {
    echo "succeeded";
} else {
    echo "failed";
}

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():

if (!is_array($response)) {
   //do we actually want to behave differently for this case? If so, should it be an exception?
} else {
   //we can iterate over the responses to see what succeded, and what failed
}

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions