Skip to content

SparkPostPromise is not chainable #208

Open
@andrews05

Description

@andrews05

The SparkPostPromise::then function does not return the result of the callback functions. This means the new promise that it returns will have no data.

$result = $sparky->request(...)->then(function($response) {
  // do something
  return $response;
})->wait();
// $result is now null!

This is important if we want to add our own middleware to transform the response.

SparkPostPromise::then could be restructured like this to fix the issue (happy to open a PR if this is suitable):

    public function then(callable $onFulfilled = null, callable $onRejected = null)
    {
        $request = $this->request;

        return $this->promise->then(function ($response) use ($request) {
            return new SparkPostResponse($response, $request);
        }, function ($exception) use ($request) {
            return new SparkPostException($exception, $request)
        })->then($onFulfilled, $onRejected);
    }

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