@@ -13,6 +13,8 @@ class ApiException extends UKFastException
13
13
public function __construct ($ response )
14
14
{
15
15
$ response ->getBody ()->rewind ();
16
+ $ this ->response = $ response ;
17
+
16
18
$ raw = $ response ->getBody ()->getContents ();
17
19
$ body = json_decode ($ raw );
18
20
$ err = json_last_error ();
@@ -22,6 +24,8 @@ public function __construct($response)
22
24
23
25
if (isset ($ body ->errors ) && is_array ($ body ->errors )) {
24
26
$ this ->errors = $ this ->getErrorsFromBody ($ body );
27
+ } elseif (isset ($ body ->message )) {
28
+ $ this ->errors = $ this ->getApiGatewayErrorFromBody ($ body );
25
29
}
26
30
27
31
if (!empty ($ this ->errors )) {
@@ -32,12 +36,6 @@ public function __construct($response)
32
36
33
37
$ this ->message = $ message ;
34
38
}
35
-
36
- if (!empty ($ response ->getHeader ('Request-ID ' )[0 ])) {
37
- $ this ->requestId = $ response ->getHeader ('Request-ID ' )[0 ];
38
- }
39
-
40
- $ this ->response = $ response ;
41
39
}
42
40
43
41
/**
@@ -86,4 +84,14 @@ private function getErrorsFromBody($body)
86
84
87
85
return $ errors ;
88
86
}
87
+
88
+ private function getApiGatewayErrorFromBody ($ body )
89
+ {
90
+ $ error = new ApiError ;
91
+ $ error ->title = 'API Gateway Error ' ;
92
+ $ error ->detail = $ body ->message ;
93
+ $ error ->status = $ this ->response ->getStatusCode ();
94
+
95
+ return [$ error ];
96
+ }
89
97
}
0 commit comments