@@ -92,12 +92,14 @@ private function sendRequestWithRetries(
9292 string $ method ,
9393 string $ path ,
9494 ?array $ params ,
95- ShipEngineConfig $ config ): array
95+ ShipEngineConfig $ config
96+ ): array
9697 {
9798 $ apiResponse = null ;
9899 for ($ retry = 0 ; $ retry <= $ config ->retries ; $ retry ++) {
99100 try {
100101 $ apiResponse = $ this ->sendRequest ($ method , $ path , $ params , $ retry , $ config );
102+ break ;
101103 } catch (\RuntimeException $ err ) {
102104 if (($ retry < $ config ->retries ) &&
103105 $ err instanceof RateLimitExceededException &&
@@ -143,6 +145,7 @@ private function sendRequest(
143145 $ client = new Client (
144146 [
145147 'base_uri ' => $ config ->baseUrl ,
148+ 'timeout ' => $ config ->timeout ,
146149 'max_retry_attempts ' => $ config ->retries
147150 ]
148151 );
@@ -175,7 +178,7 @@ private function sendRequest(
175178 // $assert->isResponse404($statusCode, $parsedResponse);
176179 // $assert->isResponse429($statusCode, $parsedResponse, $config);
177180 // $assert->isResponse500($statusCode, $parsedResponse);
178- var_dump ( $ parsedResponse );
181+
179182 return $ this ->handleResponse ($ parsedResponse );
180183 }
181184
@@ -188,61 +191,19 @@ private function sendRequest(
188191 */
189192 private function handleResponse (array $ response ): array
190193 {
191- return $ response ;
192-
194+ if (!isset ($ response ['errors ' ]) || (count ($ response ['errors ' ]) == 0 )) {
195+ return $ response ;
196+ }
193197
194- // $error = $response['error' ];
198+ $ error = $ response ['errors ' ][ 0 ];
195199
196- // switch ($error['data']['type']) {
197- // case ErrorType::ACCOUNT_STATUS:
198- // throw new AccountStatusException(
199- // $error['message'],
200- // $response['id'],
201- // $error['data']['source'],
202- // $error['data']['type'],
203- // $error['data']['code']
204- // );
205- // case ErrorType::SECURITY:
206- // throw new SecurityException(
207- // $error['message'],
208- // $response['id'],
209- // $error['data']['source'],
210- // $error['data']['type'],
211- // $error['data']['code']
212- // );
213- // case ErrorType::VALIDATION:
214- // throw new ValidationException(
215- // $error['message'],
216- // $response['id'],
217- // $error['data']['source'],
218- // $error['data']['type'],
219- // $error['data']['code']
220- // );
221- // case ErrorType::BUSINESS_RULES:
222- // throw new BusinessRuleException(
223- // $error['message'],
224- // $response['id'],
225- // $error['data']['source'],
226- // $error['data']['type'],
227- // $error['data']['code']
228- // );
229- // case ErrorType::SYSTEM:
230- // throw new SystemException(
231- // $error['message'],
232- // $response['id'],
233- // $error['data']['source'],
234- // $error['data']['type'],
235- // $error['data']['code']
236- // );
237- // default:
238- // throw new ShipEngineException(
239- // $error['message'],
240- // $response['id'],
241- // $error['data']['source'],
242- // $error['data']['type'],
243- // $error['data']['code']
244- // );
245- // }
200+ throw new ShipEngineException (
201+ $ error ['message ' ],
202+ $ response ['request_id ' ],
203+ $ error ['error_source ' ],
204+ $ error ['error_type ' ],
205+ $ error ['error_code ' ]
206+ );
246207 }
247208
248209 /**
0 commit comments