Knex update executes however catch error still exectues

Viewed 10
        db('login')
        .where('id' ,'=', id)
        .update({ 
            password: password
        })
        .then(res => res.json('success'))
        .catch(err => res.json('failed'))

So in this simple piece of code, the password does get updated but 'success' doesnt get returned. It gets updated and .catch executes after.

I even tried this

            db('login')
        .where('id' ,'=', id)
        .update({ 
            password: password
        })
        .then(res => {
         console.log('testing')
         res.json('success')})
        .catch(err => res.json('failed'))

and console.log executes but then it goes to .catch, it doesn't execute res.json('success')

if i completely get rid of the .catch part, i get the following error

.then(res => res.json('success')) ^ TypeError: res.json is not a function

the little arrow is pointing to .json but i couldnt format it properly here

0 Answers
Related