2
2
3
3
namespace Helldar \ApiResponse \Support ;
4
4
5
- use function basename ;
6
5
use Exception as BaseException ;
7
- use function get_class ;
8
6
use Illuminate \Contracts \Support \Responsable ;
9
7
use Illuminate \Http \Exceptions \HttpResponseException ;
10
-
8
+ use Illuminate \ Http \ Response as LaravelResponse ;
11
9
use Illuminate \Validation \ValidationException ;
10
+ use Symfony \Component \HttpFoundation \Response as SymfonyResponse ;
11
+ use Throwable ;
12
+
13
+ use function basename ;
14
+ use function get_class ;
12
15
use function is_object ;
13
16
use function is_subclass_of ;
14
17
use function str_replace ;
15
- use Throwable ;
16
18
17
19
final class Exception
18
20
{
@@ -40,8 +42,8 @@ public static function isThrowable($value = null): bool
40
42
public static function getCode ($ value , int $ status_code = 400 ): int
41
43
{
42
44
$ code = $ value instanceof ValidationException
43
- ? ( $ value ->status ?? $ value ->getCode ())
44
- : ( $ value ->getCode () ?? $ status_code ) ;
45
+ ? $ value ->status ?? $ value ->getCode () ?? $ status_code
46
+ : $ value ->getCode () ?? $ value -> getStatusCode () ?? $ status_code ;
45
47
46
48
return static ::correctStatusCode ($ code , $ status_code );
47
49
}
@@ -55,6 +57,12 @@ public static function getType(Throwable $class): string
55
57
56
58
public static function getData ($ exception )
57
59
{
60
+ if ($ exception instanceof SymfonyResponse || $ exception instanceof LaravelResponse) {
61
+ return method_exists ($ exception , 'getOriginalContent ' )
62
+ ? $ exception ->getOriginalContent ()
63
+ : $ exception ->getContent () ?? $ exception ->getMessage ();
64
+ }
65
+
58
66
if ($ exception instanceof Responsable || $ exception instanceof HttpResponseException) {
59
67
return $ exception ->getResponse ();
60
68
}
0 commit comments