File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -240,16 +240,25 @@ private function render(array $options)
240240 'json ' => $ options ,
241241 ]);
242242 } catch (\GuzzleHttp \Exception \ClientException $ e ) {
243+ $ message = 'No response ' ;
244+
243245 $ response = $ e ->getResponse ();
244- $ body = $ response ? $ response ->getBody () : '' ;
245- $ json = $ response ? json_decode ($ body ) : '' ;
246- $ message = $ body ;
247- if (json_last_error () === JSON_ERROR_NONE ) {
248- $ messages = [];
249- foreach ($ json as $ error ) {
250- $ messages [] = $ error ->message ;
246+
247+ /**
248+ * You could use $e->hasResponse() but that is not accurate enough,
249+ * as phpstan will be analysing against method signatures from guzzle 6 & 7
250+ */
251+ if ($ response !== null ) {
252+ $ message = $ response ->getBody ();
253+
254+ $ json = json_decode ($ message );
255+ if (json_last_error () === JSON_ERROR_NONE ) {
256+ $ messages = [];
257+ foreach ($ json as $ error ) {
258+ $ messages [] = $ error ->message ;
259+ }
260+ $ message = implode (', ' , $ messages );
251261 }
252- $ message = implode (', ' , $ messages );
253262 }
254263
255264 throw new Browserless \APIException ("Failed to render PDF: {$ message }" , $ e ->getCode (), $ e );
You can’t perform that action at this time.
0 commit comments