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

SparkPostPromise is not chainable #208

Open
andrews05 opened this issue Feb 13, 2023 · 0 comments
Open

SparkPostPromise is not chainable #208

andrews05 opened this issue Feb 13, 2023 · 0 comments

Comments

@andrews05
Copy link

andrews05 commented Feb 13, 2023

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);
    }
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

No branches or pull requests

1 participant