node:internal/errors:491
ErrorCaptureStackTrace(err);
^
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at new NodeError (node:internal/errors:400:5)
at ServerResponse.setHeader (node:_http_outgoing:663:11)
at ServerResponse.header (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\express\lib\response.js:794:10)
at ServerResponse.send (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\express\lib\response.js:174:12)
at ServerResponse.json (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\express\lib\response.js:278:15)
at ServerResponse.send (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\express\lib\response.js:162:21)
at changePassword (C:\Users\saadaoui\Desktop\chat-app\server\controllers\authCtr.js:129:9)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'ERR_HTTP_HEADERS_SENT'
}
السؤال
محمود سعداوي2
السلام عليكم.
أريد تغيير كلمة المرور للمستخدم الحالي.
قمت بالكود التالي
const changePassword = async(req,res) => { const errors = validationResult(req) if (!errors.isEmpty()) { return res.status(400).json({errors: errors.array()}) } try { const { password, newPassword} = req.body; const current_user = await User.findById( req.user ) console.log(req.body) res.send(current_user) } catch (error) { console.log(error) res.status(500).send("Server Error"); } }
هذه واجهة Postman
تظهرلي رسالة الخطأ التالية
node:internal/errors:491 ErrorCaptureStackTrace(err); ^ Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client at new NodeError (node:internal/errors:400:5) at ServerResponse.setHeader (node:_http_outgoing:663:11) at ServerResponse.header (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\express\lib\response.js:794:10) at ServerResponse.send (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\express\lib\response.js:174:12) at ServerResponse.json (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\express\lib\response.js:278:15) at ServerResponse.send (C:\Users\saadaoui\Desktop\chat-app\server\node_modules\express\lib\response.js:162:21) at changePassword (C:\Users\saadaoui\Desktop\chat-app\server\controllers\authCtr.js:129:9) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) { code: 'ERR_HTTP_HEADERS_SENT' }
الرجاء المساعدة في معالجة الخطأ.
شكرا
3 أجوبة على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.