Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
php-http-httplug
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Debian PHP Team
PEAR
php-http-httplug
Commits
16e8b6f8
Unverified
Commit
16e8b6f8
authored
3 years ago
by
Enrico Zimuel
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Allow returning a Promise in onRejected then() (#168)
parent
fc6a1399
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG.md
+7
-0
7 additions, 0 deletions
CHANGELOG.md
spec/Promise/HttpRejectedPromiseSpec.php
+16
-0
16 additions, 0 deletions
spec/Promise/HttpRejectedPromiseSpec.php
src/Promise/HttpRejectedPromise.php
+6
-1
6 additions, 1 deletion
src/Promise/HttpRejectedPromise.php
with
29 additions
and
1 deletion
CHANGELOG.md
+
7
−
0
View file @
16e8b6f8
...
...
@@ -9,6 +9,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
## [2.3.0] - 2022-02-x
### Changed
-
Enabled the
`$onRejected`
callback of
`HttpRejectedPromise`
to return a promise for implementing a retry
mechanism
[
#168
](
https://github.com/php-http/httplug/pull/168
)
## [2.2.0] - 2020-07-13
### Changed
...
...
This diff is collapsed.
Click to expand it.
spec/Promise/HttpRejectedPromiseSpec.php
+
16
−
0
View file @
16e8b6f8
...
...
@@ -4,6 +4,7 @@ namespace spec\Http\Client\Promise;
use
Http\Client\Exception
;
use
Http\Client\Exception\TransferException
;
use
Http\Client\Promise\HttpFulfilledPromise
;
use
Http\Promise\Promise
;
use
PhpSpec\ObjectBehavior
;
use
Prophecy\Argument
;
...
...
@@ -87,4 +88,19 @@ class HttpRejectedPromiseSpec extends ObjectBehavior
throw
new
\Exception
();
});
}
function
it_returns_a_promise_when_rejected
(
ResponseInterface
$response
)
{
$exception
=
new
TransferException
();
$this
->
beConstructedWith
(
$exception
);
$promise
=
$this
->
then
(
null
,
function
(
Exception
$exceptionReceived
)
use
(
$exception
,
$response
)
{
return
new
HttpFulfilledPromise
(
$response
->
getWrappedObject
());
});
$promise
->
shouldHaveType
(
'Http\Promise\Promise'
);
$promise
->
shouldHaveType
(
'Http\Client\Promise\HttpFulfilledPromise'
);
$promise
->
getState
()
->
shouldReturn
(
Promise
::
FULFILLED
);
$promise
->
wait
()
->
shouldReturnAnInstanceOf
(
'Psr\Http\Message\ResponseInterface'
);
}
}
This diff is collapsed.
Click to expand it.
src/Promise/HttpRejectedPromise.php
+
6
−
1
View file @
16e8b6f8
...
...
@@ -27,7 +27,12 @@ final class HttpRejectedPromise implements Promise
}
try
{
return
new
HttpFulfilledPromise
(
$onRejected
(
$this
->
exception
));
$result
=
$onRejected
(
$this
->
exception
);
if
(
$result
instanceof
Promise
)
{
return
$result
;
}
return
new
HttpFulfilledPromise
(
$result
);
}
catch
(
Exception
$e
)
{
return
new
self
(
$e
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment