@@ -375,10 +375,11 @@ public static function wrapResult($result = '', $queryObject = '')
375375 *
376376 * @return Result
377377 * */
378- public static function send_request ( $ queryObject = '' , $ type = '' )
378+ public static function contentstackRequest ( $ stack , $ queryObject = '' , $ type = '' , $ count = 0 )
379379 {
380- $ server_output = '' ;
381-
380+ $ retryDelay = $ stack ->retryDelay ;
381+ $ retryLimit = $ stack ->retryLimit ;
382+ $ errorRetry = $ stack ->errorRetry ;
382383 if ($ queryObject ) {
383384 if (Utility::isLivePreview ($ queryObject )) {
384385 $ queryObject ->_query ['live_preview ' ] = ($ queryObject ->contentType ->stack ->live_preview ['live_preview ' ] ?? 'init ' );
@@ -400,8 +401,8 @@ public static function send_request($queryObject = '', $type = '')
400401 $ request_headers [] = 'branch: ' .$ Headers ["branch " ];
401402 }
402403
403- $ proxy_details = $ queryObject -> contentType -> stack ->proxy ;
404- $ timeout = $ queryObject -> contentType -> stack ->timeout ;
404+ $ proxy_details = $ stack ->proxy ;
405+ $ timeout = $ stack ->timeout ;
405406
406407 curl_setopt ($ http , CURLOPT_HTTPHEADER , $ request_headers );
407408
@@ -439,37 +440,23 @@ public static function send_request($queryObject = '', $type = '')
439440
440441 // close the curl
441442 curl_close ($ http );
442- if ($ httpcode > 199 && $ httpcode < 300 ) {
443- // wrapper the server result
444- $ response = Utility::wrapResult ($ response , $ queryObject );
445-
446- }elseif ($ httpcode == 0 ){
447- $ response = array ( 'error_message ' => 'cURL couldn’t hook up with the proxy IP address and port used ' , 'error_code ' => '407 ' );
448- }
449- else {
450- $ response = Utility::wrapResult ($ response , $ httpcode );
451- }
452- }
453- $ response += ['httpcode ' => $ httpcode ];
454- return $ response ;
455- }
456-
457- public static function contentstackRequest ($ queryObject = '' , $ type = '' , $ count = 0 )
458- {
459- $ retryDelay = $ queryObject ->contentType ->stack ->retryDelay ;
460- $ retryLimit = $ queryObject ->contentType ->stack ->retryLimit ;
461- $ errorRetry = $ queryObject ->contentType ->stack ->errorRetry ;
462- $ response = Utility::send_request ($ queryObject , $ type );
463-
464- if (in_array ( $ response ['httpcode ' ] ,$ errorRetry )){
465- if ($ count < $ retryLimit ){
466- $ retryDelay = round ($ retryDelay /1000 ); //converting retry_delay from milliseconds into seconds
467- sleep ($ retryDelay ); //sleep method requires time in seconds
468- $ count += 1 ;
469- $ response = Utility::contentstackRequest ($ queryObject , $ type , $ count );
443+ if (in_array ($ httpcode ,$ errorRetry )){
444+ if ($ count < $ retryLimit ){
445+ $ retryDelay = round ($ retryDelay /1000 ); //converting retry_delay from milliseconds into seconds
446+ sleep ($ retryDelay ); //sleep method requires time in seconds
447+ $ count += 1 ;
448+ return Utility::contentstackRequest ($ stack , $ queryObject , $ type , $ count );
449+ }
450+ } else {
451+ if ($ httpcode > 199 && $ httpcode < 300 ) {
452+ // wrapper the server result
453+ $ response = Utility::wrapResult ($ response , $ queryObject );
454+ }
455+ else {
456+ throw new CSException ($ response , $ httpcode );
457+ }
470458 }
471459 }
472- unset($ response ['httpcode ' ]);
473460 return $ response ;
474461 }
475462
0 commit comments