@@ -174,45 +174,86 @@ public function patch(string $url, array $parameters) : array
174174
175175 public function put (string $ url , array $ parameters , string $ method = 'PUT ' ) : array
176176 {
177- $ json = \json_encode ($ parameters );
178- $ guzzle = new \GuzzleHttp \Client (['headers ' => $ this ->getHeaders ([
179- 'Connection ' => 'keep-alive ' ,
180- 'Content-Length ' => \strlen ($ json ),
181- 'Accept-Encoding ' => 'gzip, deflate ' ,
182- 'Host ' => $ this ->host ,
183- 'Accept ' => '*/* ' ]),
184- 'body ' => $ json , ]);
185- ;
186- $ response = $ guzzle ->request ($ method , $ url );
177+ try
178+ {
179+ $ json = \json_encode ($ parameters ['body ' ], JSON_PRETTY_PRINT );
180+ $ guzzle = new \GuzzleHttp \Client (['headers ' => $ this ->getHeaders ([
181+ 'Connection ' => 'keep-alive ' ,
182+ 'Content-Length ' => \strlen ($ json ),
183+ 'Accept-Encoding ' => 'gzip, deflate ' ,
184+ 'Host ' => $ this ->host ,
185+ 'Accept ' => '*/* ' ]),
186+ 'body ' => $ json , ]);
187+ ;
188+ $ response = $ guzzle ->request ($ method , $ url );
189+
190+ return $ this ->process ($ response );
191+ }
192+ catch (\GuzzleHttp \Exception \RequestException $ e )
193+ {
194+ $ this ->lastError = $ e ->getMessage ();
195+ $ this ->statusCode = $ e ->getResponse ()->getStatusCode ();
196+ }
187197
188- return $ this -> process ( $ response ) ;
198+ return [] ;
189199 }
190200
191201 public function delete (string $ url ) : bool
192202 {
193- $ guzzle = new \GuzzleHttp \Client (['headers ' => $ this ->getHeaders ()]);
194- $ response = $ guzzle ->request ('DELETE ' , $ url );
203+ try
204+ {
205+ $ guzzle = new \GuzzleHttp \Client (['headers ' => $ this ->getHeaders ()]);
206+ $ response = $ guzzle ->request ('DELETE ' , $ url );
195207
196- $ this ->process ($ response );
208+ $ this ->process ($ response );
197209
198- return 204 == $ this ->statusCode ;
210+ return 204 == $ this ->statusCode ;
211+ }
212+ catch (\GuzzleHttp \Exception \RequestException $ e )
213+ {
214+ $ this ->lastError = $ e ->getMessage ();
215+ $ this ->statusCode = $ e ->getResponse ()->getStatusCode ();
216+ }
217+
218+ return false ;
199219 }
200220
201221 public function get (string $ url , array $ parameters ) : array
202222 {
203- $ guzzle = new \GuzzleHttp \Client (['headers ' => $ this ->getHeaders ()]);
204- $ response = $ guzzle ->request ('GET ' , $ url );
223+ try
224+ {
225+ $ guzzle = new \GuzzleHttp \Client (['headers ' => $ this ->getHeaders ()]);
226+ $ response = $ guzzle ->request ('GET ' , $ url );
205227
206- return $ this ->process ($ response );
228+ return $ this ->process ($ response );
229+ }
230+ catch (\GuzzleHttp \Exception \RequestException $ e )
231+ {
232+ $ this ->lastError = $ e ->getMessage ();
233+ $ this ->statusCode = $ e ->getResponse ()->getStatusCode ();
234+ }
235+
236+ return [];
207237 }
208238
209239 public function post (string $ url , array $ parameters ) : array
210240 {
211- $ guzzle = new \GuzzleHttp \Client (['headers ' => $ this ->getHeaders (),
212- 'body ' => \json_encode ($ parameters ), ]);
213- $ response = $ guzzle ->request ('POST ' , $ url );
241+ try
242+ {
243+ $ json = \json_encode ($ parameters ['body ' ], JSON_PRETTY_PRINT );
244+ $ guzzle = new \GuzzleHttp \Client (['headers ' => $ this ->getHeaders (),
245+ 'body ' => $ json , ]);
246+ $ response = $ guzzle ->request ('POST ' , $ url );
214247
215- return $ this ->process ($ response );
248+ return $ this ->process ($ response );
249+ }
250+ catch (\GuzzleHttp \Exception \RequestException $ e )
251+ {
252+ $ this ->lastError = $ e ->getMessage ();
253+ $ this ->statusCode = $ e ->getResponse ()->getStatusCode ();
254+ }
255+
256+ return [];
216257 }
217258
218259 private function exec (\CurlHandle $ ch ) : bool
0 commit comments