How to use the BAD_REQUEST function from http-status-codes

Find comprehensive JavaScript http-status-codes.BAD_REQUEST code examples handpicked from public code repositorys.

87
88
89
90
91
92
93
94
95
96
97
// eslint-disable-next-line no-unused-vars
app.use((err, req, res, next) => {
  logger.logFullError(err, req.signature || `${req.method} ${req.url}`);
  const errorResponse = {};
  let status = err.isJoi
    ? HttpStatus.BAD_REQUEST
    : err.httpStatus || _.get(err, "response.status") || HttpStatus.INTERNAL_SERVER_ERROR;


  // Check if err is a GrpcError
  if (err.details != null && err.code != null) {
fork icon44
star icon17
watch icon25

+ 4 other calls in file

198
199
200
201
202
203
204
205
206
207
      "no customer created yet or merchant not exist",
      200
    );
})
.catch((err) => {
  if (!err.status) err.status = HttpStatus.BAD_REQUEST;
  return res
    .status(err.status)
    .json(new ErrorResponse(err.message, err.status));
});
fork icon0
star icon0
watch icon1

+ 29 other calls in file

1
2
3
4
5
6
7
8
9
10
11
12
const StatusCodes = require('http-status-codes');


class BadRequestError extends CustomApiError {
  constructor(message){
    super(message);
    this.statusCode = StatusCodes.BAD_REQUEST;
  }
}


module.exports = BadRequestError;
fork icon0
star icon0
watch icon0