1616// phpcs:enable
1717
1818use Mindee \Error \MindeeV2HttpException ;
19- use Mindee \Error \MindeeV2HttpUnknownError ;
19+ use Mindee \Error \MindeeV2HttpUnknownException ;
2020use Mindee \Input \InferenceParameters ;
2121use Mindee \Input \InputSource ;
2222use Mindee \Input \LocalInputSource ;
@@ -106,6 +106,17 @@ public function __construct(?string $apiKey)
106106 }
107107 }
108108
109+ /**
110+ * Sets the base url.
111+ *
112+ * @param string $value Value for the base Url.
113+ * @return void
114+ */
115+ protected function setBaseUrl (string $ value ): void
116+ {
117+ $ this ->baseUrl = $ value ;
118+ }
119+
109120 /**
110121 * Sets values from environment, if needed.
111122 *
@@ -168,7 +179,7 @@ public function reqPostInferenceEnqueue(InputSource $inputDoc, InferenceParamete
168179 * @return JobResponse|InferenceResponse The processed response object.
169180 * @throws MindeeException Throws if HTTP status indicates an error or deserialization fails.
170181 * @throws MindeeV2HttpException Throws if the HTTP status indicates an error.
171- * @throws MindeeV2HttpUnknownError Throws if the server sends an unexpected reply.
182+ * @throws MindeeV2HttpUnknownException Throws if the server sends an unexpected reply.
172183 */
173184 private function processResponse (array $ result , string $ responseType ): InferenceResponse |JobResponse
174185 {
@@ -180,7 +191,7 @@ private function processResponse(array $result, string $responseType): Inference
180191 if ($ responseData && isset ($ responseData ['status ' ])) {
181192 throw new MindeeV2HttpException (new ErrorResponse ($ responseData ));
182193 }
183- throw new MindeeV2HttpUnknownError (json_encode ($ result , JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT ));
194+ throw new MindeeV2HttpUnknownException (json_encode ($ result , JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT ));
184195 }
185196
186197 try {
@@ -248,6 +259,7 @@ private function initChannel()
248259 curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
249260 curl_setopt ($ ch , CURLOPT_CONNECTTIMEOUT , $ this ->requestTimeout );
250261 curl_setopt ($ ch , CURLOPT_SSL_VERIFYPEER , false );
262+
251263 curl_setopt ($ ch , CURLOPT_USERAGENT , $ this ->getUserAgent ());
252264 return $ ch ;
253265 }
@@ -295,6 +307,7 @@ private function inferenceGetRequest(string $inferenceId): array
295307 * @param InputSource $inputSource File to upload.
296308 * @param InferenceParameters $params Inference parameters.
297309 * @return array
310+ * @throws MindeeException Throws if the cURL operation doesn't go succeed.
298311 */
299312 private function documentEnqueuePost (
300313 InputSource $ inputSource ,
@@ -345,6 +358,11 @@ private function documentEnqueuePost(
345358 'data ' => curl_exec ($ ch ),
346359 'code ' => curl_getinfo ($ ch , CURLINFO_HTTP_CODE ),
347360 ];
361+ $ curlError = curl_error ($ ch );
362+ if (!empty ($ curlError )) {
363+ throw new MindeeException ("cURL error: \n$ curlError " );
364+ }
365+
348366 curl_close ($ ch );
349367
350368 return $ resp ;
0 commit comments