Currently, I am working on a project that utilizes Javascript alongside Node.js, Express, SuperAgent, and KnexJS for database management with Sqlite3. The issue I am facing is as follows:
Upon submitting data for updates through my API route using the PUT method, the database successfully updates but an error is displayed in the console:
PUT http://localhost:3000/user/contracts/ 500 (unknown)
Error: unknown
at Request.<anonymous> (client.js:423)
at Request.Emitter.emit (index.js:133)
at XMLHttpRequest.xhr.onreadystatechange (client.js:735)
Below are snippets of the code from my API, Routes, and Database:
api.js
const request = require('superagent')
const updateUserContract = (callback, id, contractData) => {
request
.put('http://localhost:3000/user/contracts/' + id)
.set('Content-Type', 'application/json')
.send(contractData)
.end(function (err, res) {
if (err) {
callback(err)
} else {
callback(null, "Status: 200")
}
})
}
module.exports = { updateUserContract }
routes.js
router.put('/contracts/:id', function (req, res) {
var id = req.params.id
var signatureUrl = req.body.signature_url
db.signContract(id, signatureUrl).then((result) => {
res.sendStatus(result)
})
.catch((err) => {
res.status(500).send(err)
})
})
db.js
function signContract (id, signatureUrl) {
return knex('contracts').where('id', id)
.update({ signature_url: signatureUrl }).into('contracts')
}