guzzle / promises

Promises/A+ library for PHP with synchronous support
MIT License
7.61k stars 116 forks source link

Allow throwing an exception to actually propagate #92

Closed SudoPlz closed 4 years ago

SudoPlz commented 6 years ago

Hey there,

I've got the following code:

$promise->then(
                // $onFulfilled
                function ($user) {
                   // bla bla
                },
                // $onRejected
                function ($reason) {
                    throw new Error('reset_password_token_expired');
                }
            );

but the error is being caught.

What can I do to allow it to propagate up the error chain and crash the app?

Thank you

pjeby commented 5 years ago

If you need to force a crash, you have to Promise\queue()->add() a function that throws the error.

Tobion commented 4 years ago

If you call $promise->wait(true), your exception should be thrown. See https://github.com/guzzle/promises/blob/ac2529fc650684c5cd687e2b462d046cdbed556e/src/PromiseInterface.php#L81-L82

What's the problem here? Did you forget to actually resolve/wait on the promise?

Tobion commented 4 years ago

ping @SudoPlz

SudoPlz commented 4 years ago

It's been such a long time, I don't even remember, let's close this. Thanks for pinging me.