|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Shlinkio\Shlink\Rest\Util; |
|
6
|
|
|
|
|
7
|
|
|
use Shlinkio\Shlink\Common\Exception as Common; |
|
8
|
|
|
use Shlinkio\Shlink\Core\Exception as Core; |
|
9
|
|
|
use Shlinkio\Shlink\Rest\Exception as Rest; |
|
10
|
|
|
use Throwable; |
|
11
|
|
|
|
|
12
|
|
|
class RestUtils |
|
13
|
|
|
{ |
|
14
|
|
|
/** @deprecated */ |
|
15
|
|
|
public const INVALID_SHORTCODE_ERROR = Core\ShortUrlNotFoundException::TYPE; |
|
16
|
|
|
/** @deprecated */ |
|
17
|
|
|
public const INVALID_SHORTCODE_DELETION_ERROR = Core\DeleteShortUrlException::TYPE; |
|
18
|
|
|
/** @deprecated */ |
|
19
|
|
|
public const INVALID_URL_ERROR = Core\InvalidUrlException::TYPE; |
|
20
|
|
|
/** @deprecated */ |
|
21
|
|
|
public const INVALID_ARGUMENT_ERROR = Core\ValidationException::TYPE; |
|
22
|
|
|
/** @deprecated */ |
|
23
|
|
|
public const INVALID_SLUG_ERROR = Core\NonUniqueSlugException::TYPE; |
|
24
|
|
|
/** @deprecated */ |
|
25
|
|
|
public const INVALID_CREDENTIALS_ERROR = 'INVALID_CREDENTIALS'; |
|
26
|
|
|
public const INVALID_AUTH_TOKEN_ERROR = 'INVALID_AUTH_TOKEN'; |
|
27
|
|
|
public const INVALID_AUTHORIZATION_ERROR = 'INVALID_AUTHORIZATION'; |
|
28
|
|
|
public const INVALID_API_KEY_ERROR = 'INVALID_API_KEY'; |
|
29
|
|
|
/** @deprecated */ |
|
30
|
|
|
public const NOT_FOUND_ERROR = Core\TagNotFoundException::TYPE; |
|
31
|
|
|
/** @deprecated */ |
|
32
|
|
|
public const UNKNOWN_ERROR = 'UNKNOWN_ERROR'; |
|
33
|
|
|
|
|
34
|
|
|
/** @deprecated */ |
|
35
|
1 |
|
public static function getRestErrorCodeFromException(Throwable $e): string |
|
36
|
|
|
{ |
|
37
|
|
|
switch (true) { |
|
38
|
1 |
|
case $e instanceof Core\ShortUrlNotFoundException: |
|
39
|
1 |
|
return self::INVALID_SHORTCODE_ERROR; |
|
|
|
|
|
|
40
|
1 |
|
case $e instanceof Core\InvalidUrlException: |
|
41
|
1 |
|
return self::INVALID_URL_ERROR; |
|
|
|
|
|
|
42
|
1 |
|
case $e instanceof Core\NonUniqueSlugException: |
|
43
|
|
|
return self::INVALID_SLUG_ERROR; |
|
|
|
|
|
|
44
|
1 |
|
case $e instanceof Common\InvalidArgumentException: |
|
45
|
1 |
|
case $e instanceof Core\InvalidArgumentException: |
|
46
|
1 |
|
case $e instanceof Core\ValidationException: |
|
47
|
1 |
|
return self::INVALID_ARGUMENT_ERROR; |
|
|
|
|
|
|
48
|
1 |
|
case $e instanceof Rest\AuthenticationException: |
|
49
|
1 |
|
return self::INVALID_CREDENTIALS_ERROR; |
|
|
|
|
|
|
50
|
1 |
|
case $e instanceof Core\DeleteShortUrlException: |
|
51
|
|
|
return self::INVALID_SHORTCODE_DELETION_ERROR; |
|
|
|
|
|
|
52
|
|
|
default: |
|
53
|
1 |
|
return self::UNKNOWN_ERROR; |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|