Can't seem to operate on the $response to \React\Http\Browser() 's post() #518
-
Hi, I'm running ReactPHP http v1.9.0, async v3.1.0, on PHP 7.4 in an Ubuntu 20.04 VM. Have some code like this:
It's basically just like https://github.com/clue/reactphp-buzz/blob/master/examples/04-post-json.php My Can anyone help me figure out why? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hey @mig5, it seems like you forgot to inherit your ...
)->then(function (Psr\Http\Message\ResponseInterface $response) use ($endpoint) {
syslog(LOG_INFO, 'Connection Notification sent to ' . $endpoint[url']);
}, function (Exception $e) use ($endpoint) {
syslog(LOG_DEBUG, 'error on Callback request to ' . $endpoint['url']);
});
.... Without the Hope this helps 👍 |
Beta Was this translation helpful? Give feedback.
-
@SimonFrings just a follow up to say I figured it out. My code had other problems in it which weren't related to the imported variable for use in the Specifically, in this app, I needed to properly namespace This code is now working (for both success and exceptions - nice to see HTTP code 4XX, 5XX triggers an Exception here too!):
In the logs:
Thanks again for your very helpful response! Terrific! |
Beta Was this translation helpful? Give feedback.
Hey @mig5, it seems like you forgot to inherit your
$endpoint
variable inside your closure, should be something like this:Without the
use ()
PHP won't know what$endpoint
is, thus PHP will throw and error at this point. This all is happening inside a promise and promises are swallowing exceptions and errors in the current version. We're currently working on changing this behavior to detect all unhand…