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