Using curl in egg.js will request twice.

problem description

in egg, I got the openid, through the user"s code request Wechat API. I found that I got it the first time, but it was executed twice, so ctx.body directly printed the second result, and code has been used. How to modify the request only once?

the environmental background of the problems and what methods you have tried

I have tried to use ctx.throw ("500", "xxxxx") to throw an error, which can solve the printing problem (but it has been requested twice), and it cannot set 200

related codes

class User extends Controller {
    async login() {
        const ctx = this.ctx;
        const result = await ctx.curl(
            `https://api.weixin.qq.com/sns/jscode2session?appid=${
                this.app.config.appid
            }&secret=${this.app.config.secret}&js_code=${
                ctx.query.code
            }&grant_type=authorization_code`,
            {
                method: "GET",
                dataType: "json",
                headers: this.app.config.headers
            }
        )
        console.log(result.data)
        const openid = result.data.openid
        if (openid) {
            ctx.body = {
                openid
            }
        } else {
            ctx.throw(500, "openid");
        }
    }
}

what result do you expect? What is the error message actually seen?

request only once.

Jan.17,2022

return after judgment

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-7b1c99-12863.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-7b1c99-12863.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?