1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* File: ErrorHandler.php |
4
|
|
|
* |
5
|
|
|
* @author Maciej Sławik <[email protected]> |
6
|
|
|
* Github: https://github.com/maciejslawik |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace MSlwk\FreshMail\Error; |
10
|
|
|
|
11
|
|
|
use MSlwk\FreshMail\Exception\Account\FreshMailAccountException; |
12
|
|
|
use MSlwk\FreshMail\Exception\Authorization\FreshMailAuthorizationException; |
13
|
|
|
use MSlwk\FreshMail\Exception\Campaign\FreshMailCampaignException; |
14
|
|
|
use MSlwk\FreshMail\Exception\FreshMailException; |
15
|
|
|
use MSlwk\FreshMail\Exception\Lists\FreshMailListException; |
16
|
|
|
use MSlwk\FreshMail\Exception\Message\FreshMailSmsException; |
17
|
|
|
use MSlwk\FreshMail\Exception\Message\FreshMailTransactionalEmailException; |
18
|
|
|
use MSlwk\FreshMail\Exception\SpamTest\FreshMailSpamTestException; |
19
|
|
|
use MSlwk\FreshMail\Exception\Subscriber\FreshMailSubscriberException; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class ErrorHandler |
23
|
|
|
* |
24
|
|
|
* @package MSlwk\FreshMail\Error |
25
|
|
|
*/ |
26
|
|
|
class ErrorHandler implements ErrorHandlerInterface |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @param \stdClass $error |
30
|
|
|
* @throws FreshMailAccountException |
31
|
|
|
* @throws FreshMailAuthorizationException |
32
|
|
|
* @throws FreshMailCampaignException |
33
|
|
|
* @throws FreshMailException |
34
|
|
|
* @throws FreshMailListException |
35
|
|
|
* @throws FreshMailSmsException |
36
|
|
|
* @throws FreshMailSpamTestException |
37
|
|
|
* @throws FreshMailSubscriberException |
38
|
|
|
* @throws FreshMailTransactionalEmailException |
39
|
|
|
* @return null |
40
|
|
|
*/ |
41
|
679 |
|
public function raiseException(\stdClass $error) |
42
|
|
|
{ |
43
|
679 |
|
$message = $error->message; |
44
|
679 |
|
$code = $error->code; |
45
|
|
|
|
46
|
|
|
switch ($code) { |
47
|
679 |
|
case $code >= 1000 && $code <= 1004: |
48
|
35 |
|
throw new FreshMailAuthorizationException($message, $code); |
49
|
644 |
|
case $code >= 1101 && $code <= 1109: |
50
|
581 |
|
case 1150: |
51
|
70 |
|
throw new FreshMailSmsException($message, $code); |
52
|
574 |
|
case $code >= 1201 && $code <= 1213: |
53
|
483 |
|
case $code >= 1250 && $code <= 1251: |
54
|
105 |
|
throw new FreshMailTransactionalEmailException($message, $code); |
55
|
469 |
|
case $code >= 1301 && $code <= 1305: |
56
|
420 |
|
case $code >= 1311 && $code <= 1312: |
57
|
406 |
|
case $code >= 1321 && $code <= 1322: |
58
|
392 |
|
case 1331: |
59
|
84 |
|
throw new FreshMailSubscriberException($message, $code); |
60
|
385 |
|
case $code >= 1501 && $code <= 1513: |
61
|
84 |
|
throw new FreshMailAccountException($message, $code); |
62
|
301 |
|
case $code >= 1601 && $code <= 1605: |
63
|
245 |
|
case 1611: |
64
|
63 |
|
throw new FreshMailListException($message, $code); |
65
|
238 |
|
case $code >= 1701 && $code <= 1713: |
66
|
147 |
|
case $code >= 1721 && $code <= 1726: |
67
|
98 |
|
case $code >= 1731 && $code <= 1736: |
68
|
56 |
|
case $code >= 1750 && $code <= 1751: |
69
|
42 |
|
case 1798: |
70
|
203 |
|
throw new FreshMailCampaignException($message, $code); |
71
|
35 |
|
case $code >= 1901 && $code <= 1907: |
72
|
35 |
|
throw new FreshMailSpamTestException($message, $code); |
73
|
|
|
default: |
74
|
|
|
throw new FreshMailException($message, $code); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|