22
33import com .alibaba .fastjson .JSONObject ;
44import com .netease .http .dto .*;
5+ import com .netease .http .exception .TransferCommonException ;
56import com .netease .http .util .FileUtil ;
67import com .netease .http .util .SSLUtil ;
78import com .netease .lowcode .core .annotation .NaslLogic ;
@@ -61,7 +62,7 @@ public class LCAPHttpClient {
6162 @ NaslLogic
6263 @ Deprecated
6364 @ Retryable (value = {Exception .class }, maxAttempts = 3 , backoff = @ Backoff (delay = 1000L ))
64- public String exchange (@ Required String url , @ Required String httpMethod , @ Required Map <String , String > header , @ Required Map <String , String > body ) throws IllegalArgumentException {
65+ public String exchange (@ Required String url , @ Required String httpMethod , @ Required Map <String , String > header , @ Required Map <String , String > body ) throws TransferCommonException {
6566 try {
6667 RequestParamAllBodyTypeInner requestParam = new RequestParamAllBodyTypeInner ();
6768 requestParam .setBody (body );
@@ -73,14 +74,14 @@ public String exchange(@Required String url, @Required String httpMethod, @Requi
7374 if (exchange .getStatusCode () == HttpStatus .OK ) {
7475 return exchange .getBody ();
7576 } else {
76- throw new IllegalArgumentException ( "请求http失败,返回:" + JSONObject .toJSONString (exchange ));
77+ throw new TransferCommonException ( exchange . getStatusCodeValue (), JSONObject .toJSONString (exchange ));
7778 }
7879 } catch (HttpClientErrorException e ) {
7980 logger .error ("" , e );
80- throw new IllegalArgumentException ( e .getResponseBodyAsString ());
81+ throw new TransferCommonException ( e . getStatusCode (). value (), e .getResponseBodyAsString ());
8182 } catch (Exception e ) {
8283 logger .error ("" , e );
83- throw new IllegalArgumentException (e .getMessage ());
84+ throw new TransferCommonException (e .getMessage (), e );
8485 }
8586 }
8687
@@ -97,7 +98,7 @@ public String exchange(@Required String url, @Required String httpMethod, @Requi
9798 */
9899 @ NaslLogic
99100 @ Retryable (value = {Exception .class }, maxAttempts = 3 , backoff = @ Backoff (delay = 1000L ))
100- public String exchangeV2 (@ Required String url , @ Required String httpMethod , @ Required Map <String , String > header , @ Required Map <String , String > body ) throws IllegalArgumentException {
101+ public String exchangeV2 (@ Required String url , @ Required String httpMethod , @ Required Map <String , String > header , @ Required Map <String , String > body ) throws TransferCommonException {
101102 try {
102103 RequestParamAllBodyTypeInner requestParam = new RequestParamAllBodyTypeInner ();
103104 requestParam .setBody (body );
@@ -112,7 +113,7 @@ public String exchangeV2(@Required String url, @Required String httpMethod, @Req
112113 return e .getResponseBodyAsString ();
113114 } catch (Exception e ) {
114115 logger .error ("" , e );
115- throw new IllegalArgumentException (e .getMessage ());
116+ throw new TransferCommonException (e .getMessage (), e );
116117 }
117118 }
118119
@@ -126,7 +127,7 @@ public String exchangeV2(@Required String url, @Required String httpMethod, @Req
126127 * @return
127128 */
128129 @ NaslLogic
129- public String downloadFileUploadNos (String fileUrl , String fileName , Map <String , String > header ) throws IllegalArgumentException {
130+ public String downloadFileUploadNos (String fileUrl , String fileName , Map <String , String > header ) throws TransferCommonException {
130131 File file = null ;
131132 try {
132133 RequestParamAllBodyTypeInner requestParam = new RequestParamAllBodyTypeInner ();
@@ -138,10 +139,10 @@ public String downloadFileUploadNos(String fileUrl, String fileName, Map<String,
138139 return uploadResponseDTO .result ;
139140 } catch (HttpClientErrorException e ) {
140141 logger .error ("" , e );
141- throw new IllegalArgumentException ( e .getResponseBodyAsString ());
142+ throw new TransferCommonException ( e . getStatusCode (). value (), e .getResponseBodyAsString ());
142143 } catch (Exception e ) {
143144 logger .error ("" , e );
144- throw new IllegalArgumentException (e .getMessage ());
145+ throw new TransferCommonException (e .getMessage (), e );
145146 } finally {
146147 if (file != null && file .exists ()) {
147148 file .delete ();
@@ -158,7 +159,7 @@ public String downloadFileUploadNos(String fileUrl, String fileName, Map<String,
158159 * @return
159160 */
160161 @ NaslLogic
161- public String uploadNosExchange (String fileUrl , String requestUrl , RequestParam requestParam ) throws IllegalArgumentException {
162+ public String uploadNosExchange (String fileUrl , String requestUrl , RequestParam requestParam ) throws TransferCommonException {
162163 File file = null ;
163164 try {
164165 RequestParamAllBodyTypeInner requestParamGetFile = new RequestParamAllBodyTypeInner ();
@@ -193,14 +194,14 @@ public String uploadNosExchange(String fileUrl, String requestUrl, RequestParam
193194 if (exchange .getStatusCode () == HttpStatus .OK ) {
194195 return exchange .getBody ();
195196 } else {
196- throw new IllegalArgumentException ( "请求http失败,返回:" + JSONObject .toJSONString (exchange ));
197+ throw new TransferCommonException ( exchange . getStatusCodeValue (), JSONObject .toJSONString (exchange ));
197198 }
198199 } catch (HttpClientErrorException e ) {
199200 logger .error ("" , e );
200- throw new IllegalArgumentException ( e .getResponseBodyAsString ());
201+ throw new TransferCommonException ( e . getStatusCode (). value (), e .getResponseBodyAsString ());
201202 } catch (Exception e ) {
202203 logger .error ("" , e );
203- throw new IllegalArgumentException (e .getMessage ());
204+ throw new TransferCommonException (e .getMessage (), e );
204205 } finally {
205206 if (file != null && file .exists ()) {
206207 file .delete ();
@@ -216,7 +217,7 @@ public String uploadNosExchange(String fileUrl, String requestUrl, RequestParam
216217 */
217218 @ NaslLogic
218219 @ Retryable (value = {Exception .class }, maxAttempts = 3 , backoff = @ Backoff (delay = 1000L ))
219- public String exchangeCrt (RequestParam requestParam ) throws IllegalArgumentException {
220+ public String exchangeCrt (RequestParam requestParam ) throws TransferCommonException {
220221 try {
221222 if (requestParam .getIsIgnoreCrt () == null ) {
222223 requestParam .setIsIgnoreCrt (false );
@@ -229,14 +230,14 @@ public String exchangeCrt(RequestParam requestParam) throws IllegalArgumentExcep
229230 if (exchange .getStatusCode () == HttpStatus .OK ) {
230231 return exchange .getBody ();
231232 } else {
232- throw new IllegalArgumentException ( "请求http失败,返回:" + JSONObject .toJSONString (exchange ));
233+ throw new TransferCommonException ( exchange . getStatusCodeValue (), JSONObject .toJSONString (exchange ));
233234 }
234235 } catch (HttpClientErrorException e ) {
235236 logger .error ("" , e );
236- throw new IllegalArgumentException ( e .getResponseBodyAsString ());
237+ throw new TransferCommonException ( e . getStatusCode (). value (), e .getResponseBodyAsString ());
237238 } catch (Exception e ) {
238239 logger .error ("" , e );
239- throw new IllegalArgumentException (e .getMessage ());
240+ throw new TransferCommonException (e .getMessage (), e );
240241 }
241242 }
242243
@@ -249,7 +250,7 @@ public String exchangeCrt(RequestParam requestParam) throws IllegalArgumentExcep
249250 */
250251 @ NaslLogic
251252 @ Retryable (value = {Exception .class }, maxAttempts = 3 , backoff = @ Backoff (delay = 1000L ))
252- public String exchangeAllBodyType (RequestParamAllBodyType requestParam ) throws IllegalArgumentException {
253+ public String exchangeAllBodyType (RequestParamAllBodyType requestParam ) throws TransferCommonException {
253254 try {
254255 if (requestParam .getIsIgnoreCrt () == null ) {
255256 requestParam .setIsIgnoreCrt (false );
@@ -263,14 +264,14 @@ public String exchangeAllBodyType(RequestParamAllBodyType requestParam) throws I
263264 if (exchange .getStatusCode () == HttpStatus .OK ) {
264265 return exchange .getBody ();
265266 } else {
266- throw new IllegalArgumentException ( "请求http失败,返回:" + JSONObject .toJSONString (exchange ));
267+ throw new TransferCommonException ( exchange . getStatusCodeValue (), JSONObject .toJSONString (exchange ));
267268 }
268269 } catch (HttpClientErrorException e ) {
269270 logger .error ("" , e );
270- throw new IllegalArgumentException ( e .getResponseBodyAsString ());
271+ throw new TransferCommonException ( e . getStatusCode (). value (), e .getResponseBodyAsString ());
271272 } catch (Exception e ) {
272273 logger .error ("" , e );
273- throw new IllegalArgumentException (e .getMessage ());
274+ throw new TransferCommonException (e .getMessage (), e );
274275 }
275276 }
276277
@@ -282,7 +283,7 @@ public String exchangeAllBodyType(RequestParamAllBodyType requestParam) throws I
282283 */
283284 @ NaslLogic
284285 @ Retryable (value = {Exception .class }, maxAttempts = 3 , backoff = @ Backoff (delay = 1000L ))
285- public String exchangeCrtForm (RequestParam requestParam ) throws IllegalArgumentException {
286+ public String exchangeCrtForm (RequestParam requestParam ) throws TransferCommonException {
286287 try {
287288 if (requestParam .getIsIgnoreCrt () == null ) {
288289 requestParam .setIsIgnoreCrt (false );
@@ -302,14 +303,14 @@ public String exchangeCrtForm(RequestParam requestParam) throws IllegalArgumentE
302303 if (exchange .getStatusCode () == HttpStatus .OK ) {
303304 return exchange .getBody ();
304305 } else {
305- throw new IllegalArgumentException ( "请求http失败,返回:" + JSONObject .toJSONString (exchange ));
306+ throw new TransferCommonException ( exchange . getStatusCode (). value (), JSONObject .toJSONString (exchange ));
306307 }
307308 } catch (HttpClientErrorException e ) {
308309 logger .error ("" , e );
309- throw new IllegalArgumentException ( e .getResponseBodyAsString ());
310+ throw new TransferCommonException ( e . getStatusCode (). value (), e .getResponseBodyAsString ());
310311 } catch (Exception e ) {
311312 logger .error ("" , e );
312- throw new IllegalArgumentException (e .getMessage ());
313+ throw new TransferCommonException (e .getMessage (), e );
313314 }
314315 }
315316
@@ -325,7 +326,7 @@ public String exchangeCrtForm(RequestParam requestParam) throws IllegalArgumentE
325326 */
326327 @ NaslLogic
327328 @ Retryable (value = {Exception .class }, maxAttempts = 3 , backoff = @ Backoff (delay = 1000L ))
328- public String exchangeWithoutUriEncode (@ Required String url , @ Required String httpMethod , @ Required Map <String , String > header , @ Required Map <String , String > body ) throws IllegalArgumentException {
329+ public String exchangeWithoutUriEncode (@ Required String url , @ Required String httpMethod , @ Required Map <String , String > header , @ Required Map <String , String > body ) throws TransferCommonException {
329330 try {
330331 RequestParamAllBodyTypeInner requestParam = new RequestParamAllBodyTypeInner ();
331332 requestParam .setBody (body );
@@ -337,14 +338,14 @@ public String exchangeWithoutUriEncode(@Required String url, @Required String ht
337338 if (exchange .getStatusCode () == HttpStatus .OK ) {
338339 return exchange .getBody ();
339340 } else {
340- throw new IllegalArgumentException ( "请求http失败,返回:" + JSONObject .toJSONString (exchange ));
341+ throw new TransferCommonException ( exchange . getStatusCodeValue (), JSONObject .toJSONString (exchange ));
341342 }
342343 } catch (HttpClientErrorException e ) {
343344 logger .error ("" , e );
344- throw new IllegalArgumentException ( e .getResponseBodyAsString ());
345+ throw new TransferCommonException ( e . getStatusCode (). value (), e .getResponseBodyAsString ());
345346 } catch (Exception e ) {
346347 logger .error ("" , e );
347- throw new IllegalArgumentException (e .getMessage ());
348+ throw new TransferCommonException (e .getMessage (), e );
348349 }
349350 }
350351}
0 commit comments