0 پاسخ

ارور ست هدر و async

async register(req, res, next) {
    console.log(1)
    let result = await this.ValidationData(req);
    console.log(2)
    if (result) return res.json(result);
    console.log(3)
    const newUser = new User({ ...req.body });
    console.log(4)
    await newUser.save(async err => {
        console.log(5)
        if (await err.code == 11000) {
            console.log(6)
            return res.json('user hast')
        }
        console.log(7)
    });
    console.log(8)
    return res.json('ok')
}

سلام دوستان لاگای کد من این طوری داره اجرا میشه
1
2
3
4
8
5
6
به خاطر همین ok رو اجرا میکنه بعد ارور مربودط به 11000 و میگه شما یه با هدر ست کردی دیگه نمیتونی هدر ست کنی مشکل این جاست من await هم گذاشتم ولی باز ok اول اجرا میشه