1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\Pushwoosh; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Collection; |
6
|
|
|
use RuntimeException; |
7
|
|
|
use Throwable; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Exception thrown following communication failure with the Pushwoosh API. |
11
|
|
|
*/ |
12
|
|
|
class PushwooshException extends RuntimeException |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Create a new exception for an API error. |
16
|
|
|
* |
17
|
|
|
* @param object $payload |
18
|
|
|
* @param \Throwable|null $previous |
19
|
|
|
* @return \NotificationChannels\Pushwoosh\PushwooshException |
20
|
|
|
*/ |
21
|
|
|
public static function apiError($payload, Throwable $previous = null) |
22
|
|
|
{ |
23
|
|
|
return new static(sprintf('Pushwoosh API error: %s', $payload->status_message), 0, $previous); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Create a new exception for failed transmission. |
28
|
|
|
* |
29
|
|
|
* @param \Throwable|null $previous |
30
|
|
|
* @return \NotificationChannels\Pushwoosh\PushwooshException |
31
|
|
|
*/ |
32
|
|
|
public static function failedTransmission(Throwable $previous = null) |
33
|
|
|
{ |
34
|
|
|
return new static('Failed to create message(s)', 0, $previous); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Create a new exception for unknown devices. |
39
|
|
|
* |
40
|
|
|
* @param object $payload |
41
|
|
|
* @param \Throwable|null $previous |
42
|
|
|
* @return \NotificationChannels\Pushwoosh\PushwooshException |
43
|
|
|
*/ |
44
|
|
|
public static function unknownDevices($payload, Throwable $previous = null) |
45
|
|
|
{ |
46
|
|
|
$devices = Collection::make($payload->response->UnknownDevices)->reduce(function ($carry, $devices) { |
47
|
|
|
return array_merge((array)$carry, $devices); |
48
|
|
|
}, []); |
49
|
|
|
|
50
|
|
|
return new static(sprintf('Unknown device(s) mentioned: %s', implode(', ', $devices)), 0, $previous); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|