javascript - Error is thrown but error response object is empty in Mongoose -
i trying send request api.
my code this
app.post('/api/create', (req, res, next) => { if (!req.headers || !req.headers.authorization) { return res.status(500).json({ status: 'error', err: 'no authorization header' }); } const bits = req.headers.authorization.split(' '); const scheme = bits[0]; const token = bits[1]; jwt.verify(token, 'secret', function(err, decoded) { if (!!err) { return res.status(400).json({ status: 'error', err: 'invalid credentials.' }); } // const userid = decoded.id; // if (!userid) { return res.status(400).json({ status: 'error', err: 'user id missing', }); } // const { postid } = req.params; // user.findbyid(userid).then(user => { // if (!user) { return res.status(400).json({ status: 'error', err: 'user not found', }); } // post.findbyid(postid).then(event => { // if (!post) { return res.status(400).json({ status: 'error', err: 'post not found', }); } // ... }).catch(err => { // not find post return res.status(400).json({ status: 'error', msg: 'could not find post', err }); }); }).catch(err => { // not find user return res.status(400).json({ status: 'error', msg: 'could not find user', err }); }); }); });
but receive error object
{ status: 'error', msg: 'could not find post', err: '' }
i.e. err
empty. have no idea how debug this. catching error }).catch(err => {
, expect write out error if ever reach catch()
block.
what can cause problem?
Comments
Post a Comment