调整enka的请求参数,优化请求错误时的日志记录

This commit is contained in:
Kokomi 2022-09-14 12:25:14 +08:00
parent 2ab90de918
commit 4654d99f7a
3 changed files with 19 additions and 4 deletions

View File

@ -9,7 +9,9 @@ export default new ProfileServ({
// 处理请求参数
async request (api) {
let params = { headers: { 'User-Agent': this.getCfg('userAgent') } }
let params = {
headers: { 'User-Agent': this.getCfg('userAgent') }
}
let proxy = this.getCfg('proxyAgent')
if (proxy) {
let { HttpsProxyAgent } = await Data.import('https-proxy-agent')
@ -21,6 +23,9 @@ export default new ProfileServ({
// 处理服务返回
async response (data, req) {
if (!data.playerInfo) {
if(data.error) {
console.log(`Enka ReqErr: ${data.error}`)
}
return req.err('error', 60)
}
let details = data.avatarInfoList

View File

@ -66,9 +66,19 @@ export default class ProfileReq extends Base {
let data = {}
try {
let params = reqParam.params || {}
params.timeout = params.timeout || 1000 * 10
params.timeout = params.timeout || 1000 * 20
let req = await fetch(reqParam.url, params)
data = await req.json()
data = await req.text()
if(data[0] === '<'){
let titleRet = /<title>(.+)<\/title>/.exec(data)
if(titleRet && titleRet[1]) {
data = { error: titleRet[1] }
} else {
return this.err('error', 60)
}
} else {
data = JSON.parse(data)
}
} catch (e) {
console.log('面板请求错误', e)
data = {}

View File

@ -49,7 +49,7 @@ export default class ProfileServ extends Base {
return {
url: param.api || api,
param: param.config || {}
params: param.params || {}
}
}