php - GuzzleHttp Asynchronous Request Exception -


I do not understand how I can remove exceptions from the ghazle future response handler here My code is:

  & lt ;? Php is required 'vendor / autoload.php'; $ Client = new \ GoalHappy \ Customer (); $ Req = $ client- & gt; CreateRequest ('GET', 'http://www.google.com', array ('future' = & gt; true;)); Echo "request is being sent \ n"; $ Response = $ client- & gt; Send ($ req); {$ Response-> gt; Then try (function ($ data) {echo "response received \ n"; throw a new exception ('test');}) -> Then (function () {// success handler}, function (exception exception =) {echo "error handler applied \ n"; throw $ exception;}); } Catch (exception $ e) {echo "exception catched \ n"; } "Finish \ n";  

hold blocks never reached in this case.

You are working with the promise using asynchronous ghazal requests. By using , the closed function of a futurrespons will create a promise that has been completed or rejected when the request is completed. If an error occurs while sending, the promise is rejected, which means that the function then the second callback applied. When a request is successfully completed, it is resolved, and the first callback provided to the function is then applied. When an exception is made in any of the promises, the exception is caught inside the promise and the next error in the chain is forwarded to the handler. In your example, if the request is successful, then you throw an exception which will trigger the error callback. By throwing an exception in the error callback, the exception will be forwarded to the next error callback in the futures chain, or quietly eat the error (in your case, there is no other error callback to trigger).

The adverse promise library, which is used by Ghazle, has more documents on the forward resolution of the promise and the rejection of the promise: Writing a done () function to the author of this library Seeing which can be used as a terminal word handler, which throws unconstitutional exceptions.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -