我编写了一个节点应用程序,它使用多个端点从 API 获取数据。我也在使用代理来做到这一点。我目前正在使用socks-proxy-agent为我的实例创建一个 https 代理axios来使用代理。这是完成所有这些的类:export class Checker { private region: Region private proxy: AxiosProxyConfig | false private client: AxiosInstance constructor(region: Region, proxy?: AxiosProxyConfig | false) { this.region = region; this.proxy = proxy; if (proxy) { const proxyOptions = `socks://${proxy.host}:${proxy.port}`; const httpsAgent = new SocksProxyAgent(proxyOptions); this.client = axios.create({ timeout: 5000, httpsAgent: httpsAgent }); } else { this.client = axios.create({ timeout: 5000 }); } } public check(account: Account): Promise<CheckResponse> { return new Promise((resolve, reject) => { this.client.post("xxx", { acr_values: "urn:riot:bronze", claims: "", client_id: "riot-client", nonce: 1, redirect_uri: "http://localhost/redirect", response_type: "token id_token", scope: "openid link ban lol_region", }).then((response) => { const cookies = response.headers["set-cookie"]; this.client.put( "xxx", { type: "auth", username: account.username, password: account.password, remember: false, language: "en_GB", region: this.region.login, }, { headers: { Cookie: cookies, }, } )
1 回答
陪伴而非守候
TA贡献1757条经验 获得超8个赞
当我查看您的代码时,此 api 调用this.client.post("https://auth.riotgames.com/userinfo")
没有catch
功能。通过在不同的函数中分离每个 api 调用并返回它们,您的代码变得更加清晰,并且更容易找到这些错误。
添加回答
举报
0/150
提交
取消