@@ -28,44 +28,39 @@ class Guzzle6Promise implements Promise
28
28
/**
29
29
* @var Exception
30
30
*/
31
- private $ error ;
31
+ private $ exception ;
32
32
33
33
public function __construct (PromiseInterface $ promise )
34
34
{
35
- $ this ->promise = $ promise ;
36
- $ this ->state = self ::PENDING ;
37
- }
38
-
39
- /**
40
- * {@inheritdoc}
41
- */
42
- public function then (callable $ onFulfilled = null , callable $ onRejected = null )
43
- {
44
- $ onFulfilledInternal = function ($ response ) use ($ onFulfilled ) {
35
+ $ this ->promise = $ promise ->then (function ($ response ) {
45
36
$ this ->response = $ response ;
46
37
$ this ->state = self ::FULFILLED ;
47
38
48
- return $ onFulfilled ($ this ->response );
49
- };
50
-
51
- $ onRejectedInternal = function ($ reason ) use ($ onRejected ) {
39
+ return $ response ;
40
+ }, function ($ reason ) {
52
41
if (!($ reason instanceof RequestException)) {
53
- throw new \RuntimeException ("Invalid reason " );
42
+ throw new \RuntimeException ("Invalid reason " );
54
43
}
55
44
56
- $ this ->state = self ::REJECTED ;
57
- $ this ->error = new Exception \NetworkException ($ reason ->getMessage (), $ reason ->getRequest (), $ reason );
45
+ $ this ->state = self ::REJECTED ;
46
+ $ this ->exception = new Exception \NetworkException ($ reason ->getMessage (), $ reason ->getRequest (), $ reason );
58
47
59
48
if ($ reason ->hasResponse ()) {
60
- $ this ->error = new Exception \HttpException ($ reason ->getMessage (), $ reason ->getRequest (), $ reason ->getResponse (), $ reason );
49
+ $ this ->exception = new Exception \HttpException ($ reason ->getMessage (), $ reason ->getRequest (), $ reason ->getResponse (), $ reason );
61
50
}
62
51
63
- return $ onRejected ( $ this ->error ) ;
64
- };
52
+ throw $ this ->exception ;
53
+ }) ;
65
54
66
- $ this ->promise = $ this ->promise ->then ($ onFulfilledInternal , $ onRejectedInternal );
55
+ $ this ->state = self ::PENDING ;
56
+ }
67
57
68
- return new static ($ this ->promise );
58
+ /**
59
+ * {@inheritdoc}
60
+ */
61
+ public function then (callable $ onFulfilled = null , callable $ onRejected = null )
62
+ {
63
+ return new static ($ this ->promise ->then ($ onFulfilled , $ onRejected ));
69
64
}
70
65
71
66
/**
@@ -92,13 +87,13 @@ public function getResponse()
92
87
/**
93
88
* {@inheritdoc}
94
89
*/
95
- public function getError ()
90
+ public function getException ()
96
91
{
97
92
if (self ::REJECTED !== $ this ->state ) {
98
93
throw new \LogicException ("Error not available for the current state " );
99
94
}
100
95
101
- return $ this ->error ;
96
+ return $ this ->exception ;
102
97
}
103
98
104
99
/**
0 commit comments