Reputation: 645
I am getting this error code:
PHP Warning: get_class() expects parameter 1 to be object, string given in /phalcon/vendor/clue/block-react/src/functions.php on line 90 PHP Fatal error: Uncaught UnexpectedValueException: Promise rejected with unexpected value of type in /phalcon/vendor/clue/block-react/src/functions.php:89 Stack trace:
- 0 /phalcon/vendor/clue/block-react/src/functions.php(198): Clue\React\Block\await(NULL, Object(React\EventLoop\StreamSelectLoop), NULL)
- 1 /phalcon/app/tasks/RunTask.php(96): Clue\React\Block\awaitAll(NULL, Object(React\EventLoop\StreamSelectLoop))
I'm building my promises with the following code:
$promises[] = $this->getTrades($rule->id, $exchange->id)
->then(
function ($trades) use ($handleTrades) {
foreach ($trades as $trade) {
$handleTrades[] = $trade;
}
}
);
The function is like this:
private function getTrades($rule, $exchange) {
$deferred = new React\Promise\Deferred();
//...
if (empty($trades->count())) {
$deferred->reject("No trades found for rule $rule");
} else {
$deferred->resolve($trades);
}
return $deferred->promise();
}
How do I solve this?
Upvotes: 0
Views: 358
Reputation: 645
As Furgas mentioned above I needed to add the error handling function in the promise.
Upvotes: 0
Reputation: 2844
The real reason is Fatal error: Uncaught UnexpectedValueException
, not the warning. As you can see the clue/reactphp-block
library expects an Exception
in your reject
function. Try:
$deferred->reject(new \Exception("No trades found for rule $rule"));
Upvotes: 1