feat:request优化
This commit is contained in:
		
							parent
							
								
									f0c6451623
								
							
						
					
					
						commit
						c7dd0aa000
					
				| @ -10,7 +10,7 @@ const config = { | ||||
|     host:GlobalConfig.host, | ||||
| } | ||||
| 
 | ||||
| let httpRequest = http.createHttp(); | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * @author: Renjun Su | ||||
| @ -25,13 +25,14 @@ let httpRequest = http.createHttp(); | ||||
| 
 | ||||
| export default async function request(req: any) { | ||||
|     const {url,params = {},data = {},xml,method = 'get',host,isNewCenter = false} = req; | ||||
|     let httpRequest = http.createHttp(); | ||||
|     const options = { | ||||
|         method: http.RequestMethod[method.toUpperCase()], | ||||
|         header: { | ||||
|             'Content-Type': xml ? 'text/xml' : 'application/json' | ||||
|         }, | ||||
|         extraData: xml ? data : JSON.stringify(data), | ||||
|         // connectTimeout:120000,
 | ||||
|         connectTimeout:120000, | ||||
|     } | ||||
|     //params转url拼接参数
 | ||||
|     let paramsStr  = Reflect.ownKeys(params).reduce((p: string, n: string) => (`${p}${n}=${params[n]}&`), '?') || ''; | ||||
| @ -93,7 +94,7 @@ export default async function request(req: any) { | ||||
|             return res | ||||
|         } | ||||
|     } catch (e) { | ||||
|         console.info('surenjunerror',JSON.stringify(e)) | ||||
|         console.info('test-error' + url  + ' error:resp: '+ JSON.stringify(e)) | ||||
|         if(!e||!(e?.message)){ | ||||
|             return false | ||||
|         } | ||||
| @ -108,9 +109,8 @@ export default async function request(req: any) { | ||||
|             case 2300028: return 2300028 | ||||
|             default: | ||||
|         } | ||||
|         return false | ||||
|         console.info('test-error' + url  + ' error:resp: '+ JSON.stringify(e)) | ||||
|         httpRequest.destroy(); | ||||
|         return false | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user