File tree Expand file tree Collapse file tree 3 files changed +15
-8
lines changed Expand file tree Collapse file tree 3 files changed +15
-8
lines changed Original file line number Diff line number Diff line change 6
6
7
7
use Psr \Http \Message \ResponseInterface ;
8
8
use RuntimeException ;
9
+ use Throwable ;
9
10
10
11
class CouldNotSendNotification extends RuntimeException
11
12
{
12
- public static function pushbulletRespondedWithAnError (ResponseInterface $ response ): self
13
+ public static function pushbulletRespondedWithAnError (ResponseInterface $ response, Throwable $ previous = null ): self
13
14
{
14
15
$ code = $ response ->getStatusCode ();
15
16
16
17
$ message = $ response ->getBody ();
17
18
18
- return new self ("Pushbullet responded with error: ` {$ code } - {$ message }`. " );
19
+ return new self ("Pushbullet responded with error: ` {$ code } - {$ message }`. " , 0 , $ previous );
19
20
}
20
21
21
22
public static function providedEmailIsInvalid (string $ email ): self
22
23
{
23
24
return new self ("Provided email ` {$ email }` of `notifiable` is not valid. " );
24
25
}
25
26
26
- public static function couldNotCommunicateWithPushbullet (): self
27
+ public static function couldNotCommunicateWithPushbullet (Throwable $ previous = null ): self
27
28
{
28
- return new self ('Could not connect to Pushbullet API. ' );
29
+ return new self ('Could not connect to Pushbullet API. ' , 0 , $ previous );
29
30
}
30
31
}
Original file line number Diff line number Diff line change @@ -68,9 +68,9 @@ public function send($params): ResponseInterface
68
68
'headers ' => $ this ->getHeaders (),
69
69
]);
70
70
} catch (ClientException $ exception ) {
71
- throw CouldNotSendNotification::pushbulletRespondedWithAnError ($ exception ->getResponse ());
71
+ throw CouldNotSendNotification::pushbulletRespondedWithAnError ($ exception ->getResponse (), $ exception );
72
72
} catch (Exception $ exception ) {
73
- throw CouldNotSendNotification::couldNotCommunicateWithPushbullet ();
73
+ throw CouldNotSendNotification::couldNotCommunicateWithPushbullet ($ exception );
74
74
}
75
75
}
76
76
}
Original file line number Diff line number Diff line change 4
4
5
5
namespace NotificationChannels \Pushbullet \Test \Exceptions ;
6
6
7
+ use Exception ;
7
8
use NotificationChannels \Pushbullet \Exceptions \CouldNotSendNotification ;
8
9
use PHPUnit \Framework \TestCase ;
9
10
use Psr \Http \Message \ResponseInterface ;
@@ -24,12 +25,14 @@ public function invalid_email_exception_can_be_created(): void
24
25
/** @test */
25
26
public function pushbullet_connection_exception_can_be_created (): void
26
27
{
27
- $ exception = CouldNotSendNotification::couldNotCommunicateWithPushbullet ();
28
+ $ previousException = new Exception ();
29
+ $ exception = CouldNotSendNotification::couldNotCommunicateWithPushbullet ($ previousException );
28
30
29
31
$ this ->assertEquals (
30
32
'Could not connect to Pushbullet API. ' ,
31
33
$ exception ->getMessage ()
32
34
);
35
+ $ this ->assertSame ($ previousException , $ exception ->getPrevious ());
33
36
}
34
37
35
38
/** @test */
@@ -45,11 +48,14 @@ public function pushbullet_error_exception_can_be_created(): void
45
48
->method ('getBody ' )
46
49
->willReturn ('Oops ' );
47
50
48
- $ exception = CouldNotSendNotification::pushbulletRespondedWithAnError ($ response );
51
+ $ previousException = new Exception ();
52
+
53
+ $ exception = CouldNotSendNotification::pushbulletRespondedWithAnError ($ response , $ previousException );
49
54
50
55
$ this ->assertEquals (
51
56
'Pushbullet responded with error: `400 - Oops`. ' ,
52
57
$ exception ->getMessage ()
53
58
);
59
+ $ this ->assertSame ($ previousException , $ exception ->getPrevious ());
54
60
}
55
61
}
You can’t perform that action at this time.
0 commit comments