Skip to content

Commit

Permalink
fix(deps): bump http-status-codes from 1.4.0 to 2.1.2 (#229)
Browse files Browse the repository at this point in the history
* fix(deps): bump http-status-codes from 1.4.0 to 2.1.2

Bumps [http-status-codes](https://github.com/prettymuchbryce/node-http-status) from 1.4.0 to 2.1.2.
- [Release notes](https://github.com/prettymuchbryce/node-http-status/releases)
- [Commits](prettymuchbryce/http-status-codes@v1.4.0...2.1.2)

Signed-off-by: dependabot[bot] <support@github.com>

* refactor: import StatusCodes from http-status-codes

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Antariksh Mahajan <antarikshmahajan@gmail.com>
  • Loading branch information
dependabot[bot] and mantariksh committed Aug 31, 2020
1 parent c09fef1 commit d69e081
Show file tree
Hide file tree
Showing 36 changed files with 306 additions and 288 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
"glob": "^7.1.2",
"has-ansi": "^4.0.0",
"helmet": "^3.21.3",
"http-status-codes": "^1.4.0",
"http-status-codes": "^2.1.2",
"intl-tel-input": "~12.1.6",
"json-stringify-deterministic": "^1.0.1",
"json-stringify-safe": "^5.0.1",
Expand Down
24 changes: 13 additions & 11 deletions src/app/controllers/admin-console.server.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
const mongoose = require('mongoose')
const moment = require('moment-timezone')
const HttpStatus = require('http-status-codes')
const { StatusCodes } = require('http-status-codes')

const getLoginModel = require('../models/login.server.model').default
const getSubmissionModel = require('../models/submission.server.model').default
Expand Down Expand Up @@ -534,7 +534,7 @@ const getExampleFormsUsing = (
x.timeText = parseTime(x.lastSubmission)
})
const totalNumResults = _.get(totalCount, '[0].count', 0)
return cb(null, HttpStatus.OK, { forms: pageResults, totalNumResults })
return cb(null, StatusCodes.OK, { forms: pageResults, totalNumResults })
})
} else {
mongoQuery = mongoQuery
Expand All @@ -544,12 +544,12 @@ const getExampleFormsUsing = (
pageResults.forEach((x) => {
x.timeText = parseTime(x.lastSubmission)
})
return cb(null, HttpStatus.OK, { forms: pageResults })
return cb(null, StatusCodes.OK, { forms: pageResults })
})
}

mongoQuery.catch((err) => {
return cb(err, HttpStatus.INTERNAL_SERVER_ERROR, {
return cb(err, StatusCodes.INTERNAL_SERVER_ERROR, {
message: 'Error in retrieving example forms.',
})
})
Expand Down Expand Up @@ -632,7 +632,7 @@ const getSingleExampleFormUsing = (
cb,
) => {
if (!formId || !mongoose.Types.ObjectId.isValid(formId)) {
return cb(null, HttpStatus.BAD_REQUEST, {
return cb(null, StatusCodes.BAD_REQUEST, {
message: 'Form URL is missing/invalid.',
})
}
Expand All @@ -644,18 +644,18 @@ const getSingleExampleFormUsing = (
.exec((err, result) => {
// Error
if (err) {
return cb(err, HttpStatus.INTERNAL_SERVER_ERROR, {
return cb(err, StatusCodes.INTERNAL_SERVER_ERROR, {
message: 'Error in retrieving example forms.',
})
}
if (!result) {
return cb(err, HttpStatus.NOT_FOUND, { message: 'No results found.' })
return cb(err, StatusCodes.NOT_FOUND, { message: 'No results found.' })
}

let [form] = result
if (!form) {
// The form data was not retrieved (formId likely invalid)
return cb(err, HttpStatus.NOT_FOUND, {
return cb(err, StatusCodes.NOT_FOUND, {
message: 'Error in retrieving template form - form not found.',
})
}
Expand All @@ -677,7 +677,7 @@ const getSingleExampleFormUsing = (
form.avgFeedback = submissionDetails.avgFeedback
form.timeText = parseTime(form.lastSubmission)
}
return cb(err, HttpStatus.OK, { form })
return cb(err, StatusCodes.OK, { form })
})
})
}
Expand Down Expand Up @@ -814,10 +814,12 @@ exports.getLoginStats = function (req, res) {
error,
})
return res
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.status(StatusCodes.INTERNAL_SERVER_ERROR)
.send('Error in retrieving billing records')
} else if (!loginStats) {
return res.status(HttpStatus.NOT_FOUND).send('No billing records found')
return res
.status(StatusCodes.NOT_FOUND)
.send('No billing records found')
} else {
logger.info({
message: `Billing search for ${esrvcId} by ${
Expand Down
50 changes: 25 additions & 25 deletions src/app/controllers/admin-forms.server.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const mongoose = require('mongoose')
const moment = require('moment-timezone')
const _ = require('lodash')
const JSONStream = require('JSONStream')
const HttpStatus = require('http-status-codes')
const { StatusCodes } = require('http-status-codes')
const get = require('lodash/get')

const logger = require('../../config/logger').createLoggerWithLabel(module)
Expand Down Expand Up @@ -78,17 +78,17 @@ function makeModule(connection) {

let statusCode
if (err.name === 'ValidationError') {
statusCode = HttpStatus.UNPROCESSABLE_ENTITY
statusCode = StatusCodes.UNPROCESSABLE_ENTITY
} else if (err.name === 'VersionError') {
statusCode = HttpStatus.CONFLICT
statusCode = StatusCodes.CONFLICT
} else if (
err.name === 'FormSizeError' || // FormSG-imposed limit in pre-validate hook
err instanceof RangeError || // exception when Mongoose breaches Mongo 16MB size limit
(err.name === 'MongoError' && err.code === 10334) // MongoDB Invalid BSON error
) {
statusCode = HttpStatus.REQUEST_TOO_LONG // HTTP 413 Payload Too Large
statusCode = StatusCodes.REQUEST_TOO_LONG // HTTP 413 Payload Too Large
} else {
statusCode = HttpStatus.INTERNAL_SERVER_ERROR
statusCode = StatusCodes.INTERNAL_SERVER_ERROR
}

return res.status(statusCode).send({
Expand Down Expand Up @@ -239,7 +239,7 @@ function makeModule(connection) {
*/
isFormActive: function (req, res, next) {
if (req.form.status === 'ARCHIVED') {
return res.status(HttpStatus.NOT_FOUND).send({
return res.status(StatusCodes.NOT_FOUND).send({
message: 'Form has been archived',
})
} else {
Expand All @@ -254,7 +254,7 @@ function makeModule(connection) {
*/
isFormEncryptMode: function (req, res, next) {
if (req.form.responseMode !== 'encrypt') {
return res.status(HttpStatus.UNPROCESSABLE_ENTITY).send({
return res.status(StatusCodes.UNPROCESSABLE_ENTITY).send({
message: 'Form is not encrypt mode',
})
}
Expand All @@ -267,7 +267,7 @@ function makeModule(connection) {
*/
create: function (req, res) {
if (!req.body.form) {
return res.status(HttpStatus.BAD_REQUEST).send({
return res.status(StatusCodes.BAD_REQUEST).send({
message: 'Invalid Input',
})
}
Expand Down Expand Up @@ -314,7 +314,7 @@ function makeModule(connection) {
},
})
return res
.status(HttpStatus.BAD_REQUEST)
.status(StatusCodes.BAD_REQUEST)
.send({ message: 'Invalid update to form' })
} else {
const { error, formFields } = getEditedFormFields(
Expand All @@ -331,7 +331,7 @@ function makeModule(connection) {
},
error,
})
return res.status(HttpStatus.BAD_REQUEST).send({ message: error })
return res.status(StatusCodes.BAD_REQUEST).send({ message: error })
}
form.form_fields = formFields
delete updatedForm.editFormField
Expand Down Expand Up @@ -393,7 +393,7 @@ function makeModule(connection) {
return respondOnMongoError(req, res, err)
} else if (!form) {
return res
.status(HttpStatus.NOT_FOUND)
.status(StatusCodes.NOT_FOUND)
.send({ message: 'Form not found for duplication' })
} else {
let responseMode = req.body.responseMode || 'email'
Expand Down Expand Up @@ -470,7 +470,7 @@ function makeModule(connection) {
if (err) {
return respondOnMongoError(req, res, err)
} else if (!forms) {
return res.status(HttpStatus.NOT_FOUND).send({
return res.status(StatusCodes.NOT_FOUND).send({
message: 'No user-created and collaborated-on forms found',
})
}
Expand All @@ -493,7 +493,7 @@ function makeModule(connection) {
return respondOnMongoError(req, res, err)
} else if (!feedback) {
return res
.status(HttpStatus.NOT_FOUND)
.status(StatusCodes.NOT_FOUND)
.send({ message: 'No feedback found' })
} else {
let sum = 0
Expand Down Expand Up @@ -546,7 +546,7 @@ function makeModule(connection) {
},
error: err,
})
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).send({
return res.status(StatusCodes.INTERNAL_SERVER_ERROR).send({
message: errorHandler.getMongoErrorMessage(err),
})
} else {
Expand All @@ -573,7 +573,7 @@ function makeModule(connection) {
},
error: err,
})
res.status(HttpStatus.INTERNAL_SERVER_ERROR).send({
res.status(StatusCodes.INTERNAL_SERVER_ERROR).send({
message: 'Error retrieving from database.',
})
})
Expand All @@ -587,7 +587,7 @@ function makeModule(connection) {
},
error: err,
})
res.status(HttpStatus.INTERNAL_SERVER_ERROR).send({
res.status(StatusCodes.INTERNAL_SERVER_ERROR).send({
message: 'Error converting feedback to JSON',
})
})
Expand All @@ -601,7 +601,7 @@ function makeModule(connection) {
},
error: err,
})
res.status(HttpStatus.INTERNAL_SERVER_ERROR).send({
res.status(StatusCodes.INTERNAL_SERVER_ERROR).send({
message: 'Error writing feedback to HTTP stream',
})
})
Expand All @@ -624,10 +624,10 @@ function makeModule(connection) {
!('comment' in req.body)
) {
return res
.status(HttpStatus.BAD_REQUEST)
.status(StatusCodes.BAD_REQUEST)
.send('Form feedback data not passed in')
} else {
return res.status(HttpStatus.OK).send('Successfully received feedback')
return res.status(StatusCodes.OK).send('Successfully received feedback')
}
},
/**
Expand Down Expand Up @@ -684,7 +684,7 @@ function makeModule(connection) {
createPresignedPostForImages: function (req, res) {
if (!VALID_UPLOAD_FILE_TYPES.includes(req.body.fileType)) {
return res
.status(HttpStatus.BAD_REQUEST)
.status(StatusCodes.BAD_REQUEST)
.send(`Your file type "${req.body.fileType}" is not supported`)
}

Expand Down Expand Up @@ -712,9 +712,9 @@ function makeModule(connection) {
},
error: err,
})
return res.status(HttpStatus.BAD_REQUEST).send(err)
return res.status(StatusCodes.BAD_REQUEST).send(err)
} else {
return res.status(HttpStatus.OK).send(presignedPostObject)
return res.status(StatusCodes.OK).send(presignedPostObject)
}
},
)
Expand All @@ -731,7 +731,7 @@ function makeModule(connection) {
createPresignedPostForLogos: function (req, res) {
if (!VALID_UPLOAD_FILE_TYPES.includes(req.body.fileType)) {
return res
.status(HttpStatus.BAD_REQUEST)
.status(StatusCodes.BAD_REQUEST)
.send(`Your file type "${req.body.fileType}" is not supported`)
}

Expand Down Expand Up @@ -759,9 +759,9 @@ function makeModule(connection) {
},
error: err,
})
return res.status(HttpStatus.BAD_REQUEST).send(err)
return res.status(StatusCodes.BAD_REQUEST).send(err)
} else {
return res.status(HttpStatus.OK).send(presignedPostObject)
return res.status(StatusCodes.OK).send(presignedPostObject)
}
},
)
Expand Down
Loading

0 comments on commit d69e081

Please sign in to comment.