[misc] fix express deprecations

Co-Authored-By: Jakob Ackermann <jakob.ackermann@overleaf.com>
This commit is contained in:
Ersun Warncke 2020-03-18 10:07:01 -04:00 committed by Jakob Ackermann
parent 7693883c77
commit 06ec5556b0
3 changed files with 23 additions and 22 deletions

View file

@ -52,7 +52,7 @@ app.post(
bodyParser.json({ limit: (Settings.max_doc_length + 64 * 1024) * 2 }),
HttpController.updateDoc
)
app.del('/project/:project_id/doc/:doc_id', HttpController.deleteDoc)
app.delete('/project/:project_id/doc/:doc_id', HttpController.deleteDoc)
app.post('/project/:project_id/archive', HttpController.archiveAllDocs)
app.post('/project/:project_id/unarchive', HttpController.unArchiveAllDocs)
@ -65,9 +65,9 @@ app.get('/status', (req, res) => res.send('docstore is alive'))
app.use(function (error, req, res, next) {
logger.error({ err: error, req }, 'request errored')
if (error instanceof Errors.NotFoundError) {
return res.send(404)
return res.sendStatus(404)
} else {
return res.send(500, 'Oops, something went wrong')
return res.status(500).send('Oops, something went wrong')
}
})

View file

@ -35,9 +35,9 @@ module.exports = HttpController = {
}
logger.log({ doc_id, project_id }, 'got doc')
if (doc == null) {
return res.send(404)
return res.sendStatus(404)
} else if (doc.deleted && !include_deleted) {
return res.send(404)
return res.sendStatus(404)
} else {
return res.json(HttpController._buildDocView(doc))
}
@ -56,7 +56,7 @@ module.exports = HttpController = {
return next(error)
}
if (doc == null) {
return res.send(404)
return res.sendStatus(404)
} else {
res.setHeader('content-type', 'text/plain')
return res.send(HttpController._buildRawDocView(doc))
@ -118,19 +118,19 @@ module.exports = HttpController = {
if (lines == null || !(lines instanceof Array)) {
logger.error({ project_id, doc_id }, 'no doc lines provided')
res.send(400) // Bad Request
res.sendStatus(400) // Bad Request
return
}
if (version == null || typeof version === !'number') {
logger.error({ project_id, doc_id }, 'no doc version provided')
res.send(400) // Bad Request
res.sendStatus(400) // Bad Request
return
}
if (ranges == null) {
logger.error({ project_id, doc_id }, 'no doc ranges provided')
res.send(400) // Bad Request
res.sendStatus(400) // Bad Request
return
}
@ -174,7 +174,7 @@ module.exports = HttpController = {
if (error != null) {
return next(error)
}
return res.send(204)
return res.sendStatus(204)
})
},
@ -218,7 +218,7 @@ module.exports = HttpController = {
if (error != null) {
return next(error)
}
return res.send(204)
return res.sendStatus(204)
})
},
@ -232,7 +232,7 @@ module.exports = HttpController = {
if (error != null) {
return next(error)
}
return res.send(200)
return res.sendStatus(200)
})
},
@ -246,7 +246,7 @@ module.exports = HttpController = {
if (error != null) {
return next(error)
}
return res.send(204)
return res.sendStatus(204)
})
},
@ -254,9 +254,9 @@ module.exports = HttpController = {
return HealthChecker.check(function (err) {
if (err != null) {
logger.err({ err }, 'error performing health check')
return res.send(500)
return res.sendStatus(500)
} else {
return res.send(200)
return res.sendStatus(200)
}
})
}

View file

@ -37,6 +37,7 @@ describe('HttpController', function () {
})
this.res = {
send: sinon.stub(),
sendStatus: sinon.stub(),
json: sinon.stub(),
setHeader: sinon.stub()
}
@ -111,7 +112,7 @@ describe('HttpController', function () {
it('should return 404 if the query string delete is not set ', function () {
this.HttpController.getDoc(this.req, this.res, this.next)
return this.res.send.calledWith(404).should.equal(true)
return this.res.sendStatus.calledWith(404).should.equal(true)
})
return it('should return the doc as JSON if include_deleted is set to true', function () {
@ -374,7 +375,7 @@ describe('HttpController', function () {
})
return it('should return a 400 (bad request) response', function () {
return this.res.send.calledWith(400).should.equal(true)
return this.res.sendStatus.calledWith(400).should.equal(true)
})
})
@ -390,7 +391,7 @@ describe('HttpController', function () {
})
return it('should return a 400 (bad request) response', function () {
return this.res.send.calledWith(400).should.equal(true)
return this.res.sendStatus.calledWith(400).should.equal(true)
})
})
@ -406,7 +407,7 @@ describe('HttpController', function () {
})
return it('should return a 400 (bad request) response', function () {
return this.res.send.calledWith(400).should.equal(true)
return this.res.sendStatus.calledWith(400).should.equal(true)
})
})
@ -447,7 +448,7 @@ describe('HttpController', function () {
})
return it('should return a 204 (No Content)', function () {
return this.res.send.calledWith(204).should.equal(true)
return this.res.sendStatus.calledWith(204).should.equal(true)
})
})
@ -465,7 +466,7 @@ describe('HttpController', function () {
})
return it('should return a 204 (No Content)', function () {
return this.res.send.calledWith(204).should.equal(true)
return this.res.sendStatus.calledWith(204).should.equal(true)
})
})
@ -484,7 +485,7 @@ describe('HttpController', function () {
})
return it('should return 204', function () {
return sinon.assert.calledWith(this.res.send, 204)
return sinon.assert.calledWith(this.res.sendStatus, 204)
})
})
})