1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yproximite\WannaSpeakBundle\Exception\Api; |
6
|
|
|
|
7
|
|
|
abstract class WannaSpeakApiException extends \RuntimeException implements WannaSpeakApiExceptionInterface |
8
|
|
|
{ |
9
|
|
|
private $statusCode; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @return static |
13
|
|
|
*/ |
14
|
|
|
public static function create(int $statusCode, string $message) |
15
|
|
|
{ |
16
|
|
|
switch ($statusCode) { |
17
|
|
|
case 401: |
18
|
|
|
if ('Name already Exists' === $message) { |
19
|
|
|
throw new SoundNameAlreadyExistsException($statusCode, $message); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
throw new AuthFailedException($statusCode, $message); |
23
|
|
|
case 403: |
24
|
|
|
throw new BadAccountException($statusCode, $message); |
25
|
|
|
case 404: |
26
|
|
|
throw new UnknownMethodException($statusCode, $message); |
27
|
|
|
case 405: |
28
|
|
|
throw new MethodNotImplementedException($statusCode, $message); |
29
|
|
|
case 406: |
30
|
|
|
throw new NoDidAvailableForRegionException($statusCode, $message); |
31
|
|
|
case 407: |
32
|
|
|
if ('DID not exists or not owned' === $message) { |
33
|
|
|
throw new DidNotExistsOrNotOwnedException($statusCode, $message); |
34
|
|
|
} elseif ('DID already reserved or not tested' === $message) { |
35
|
|
|
throw new DidAlreadyReservedException($statusCode, $message); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
throw new UnknownException($statusCode, $message); |
39
|
|
|
case 410: |
40
|
|
|
throw new CantUseDidAsDestinationException($statusCode, $message); |
41
|
|
|
case 500: |
42
|
|
|
throw new MissingArgumentsException($statusCode, $message); |
43
|
|
|
case 501: |
44
|
|
|
throw new UnknownApiException($statusCode, $message); |
45
|
|
|
default: |
46
|
|
|
throw new UnknownException(-1, $message); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function __construct(int $statusCode, string $message) |
51
|
|
|
{ |
52
|
|
|
parent::__construct($message); |
53
|
|
|
$this->statusCode = $statusCode; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getStatusCode(): int |
57
|
|
|
{ |
58
|
|
|
return $this->statusCode; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|