How to use the http-status.BAD_REQUEST function in http-status

To help you get started, we’ve selected a few http-status examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zenprotocol / explorer / server / components / api / transactions / transactionsController.js View on Github external
asset,
          amount
        };
      });

      for (let i = 0; i < tx.inputs.length; i++) {
        const input = tx.inputs[i];
        const outpoint = {
          txHash: input.input.txHash.hash,
          index: input.input.index,
        };
        // search for this tx and index
        const output = await outputsDAL.findOutpoint(outpoint.txHash, outpoint.index);

        if (!output) {
          throw new HttpError(httpStatus.BAD_REQUEST, 'One of the inputs is not yet in the blockchain');
        }

        txCustom.Inputs.push({
          id: i + 1, // fake id
          Output: output,
        });
      }

      const assets = getTransactionAssets(txCustom);
      res.status(httpStatus.OK).json(jsonResponse.create(httpStatus.OK, assets));
    } catch (error) {
      throw new HttpError(error.status || httpStatus.INTERNAL_SERVER_ERROR, error.customMessage);
    }
  },
  create: async function(req, res) {
github thanhle09t2bkdn / blog-server-es7 / server / helpers / Response.js View on Github external
    static error(res, e, code = HTTPStatus.BAD_REQUEST) {
        let error = e;
        if (typeof e === 'string') {
            error = new Error(e);
        }
        if (env === 'development') {
            console.log(error);
        }
        return res
            .status(code)
            .json({
                error: {
                    message: error.message,
                    statusCode: code
                },
            });
    }
github garage-it / SmartHouse-backend / src / API / switcher-statistics / switcher-statistics.controller.js View on Github external
function query(req, res, next) {
    if (!req.query.period || ! PERIOD_TO_INTERVAL.hasOwnProperty(req.query.period)) {
        const err = new APIError('Period is not provided or wrong', httpStatus.BAD_REQUEST);
        return next(err);
    }

    if (!req.query.sensor) {
        const err = new APIError('Sensor is not provided', httpStatus.BAD_REQUEST);
        return next(err);
    }

    const data = [{
        name: 'Time ON',
        value: Math.floor((Math.random() * 100) + 1)
    }, {
        name: 'Time OFF',
        value: Math.floor((Math.random() * 100) + 1)
    }];
github roman-sachenko / boilerplate-express-entity-based / app / utils / apiErrors / BadRequest.js View on Github external
constructor(message) {
    super(message || 'Bad Request', httpStatus.BAD_REQUEST);
  }
};
github WaftTech / WaftEngine / server / modules / Users / uservalidation.js View on Github external
msg: userConfig.validationMessage.districtInvalid,
        },
      ],
    },
    {
      field: 'tempaddress.vdc',
      validate: [
        {
          condition: 'IsMONGOID',
          msg: userConfig.validationMessage.vdcInvalid,
        },
      ],
    },
  ]);
  if (!isEmpty(errors)) {
    return otherHelper.sendResponse(res, HttpStatus.BAD_REQUEST, false, null, errors, 'Validation Error.', null);
  } else {
    return next();
  }
};
github SoftwareEngineeringDaily / software-engineering-daily-api / server / controllers / job.controller.js View on Github external
if (!job) {
        return next(new APIError('Job not found', httpStatus.NOT_FOUND));
      }

      if (job.postedUser.toString() === req.user._id.toString()) {
        return next(new APIError('Unable to apply for a job you posted', httpStatus.FORBIDDEN));
      }
      const today = new Date().getDate();

      if (job.isDeleted || (job.expirationDate && job.expirationDate < today)) {
        return next(new APIError('Job not found', httpStatus.NOT_FOUND));
      }

      if (!req.file) {
        return next(new APIError('Resume is required', httpStatus.BAD_REQUEST));
      }

      if (!req.body.coveringLetter) {
        return next(new APIError('Covering letter is required', httpStatus.BAD_REQUEST));
      }

      const msg = {
        to: job.applicationEmailAddress,
        from: config.email.fromAddress,
        subject: `Job Application : ${job.title}`,
        text: req.body.coveringLetter,
        attachments: [
          {
            content: req.file.buffer.toString('base64'),
            filename: req.file.originalname,
            type: req.file.mimetype,
github WaftTech / WaftEngine / server / modules / blog / blogValidation.js View on Github external
validation.catValidate = (req, res, next) => {
  const data = req.body;
  const validateArray = [
    {
      field: 'title',
      validate: [
        {
          condition: 'IsEmpty',
          msg: blogConfig.validate.empty,
        },
      ],
    },
  ];
  const errors = otherHelper.validation(data, validateArray);
  if (!isEmpty(errors)) {
    return otherHelper.sendResponse(res, httpStatus.BAD_REQUEST, false, null, errors, 'invalid input', null);
  } else {
    next();
  }
};
module.exports = validation;
github deepstreamIO / deepstream.io / src / services / http / node / node-http.ts View on Github external
this.jsonBodyParser(request, response, (err: Error | null) => {
      if (err) {
        this.terminateResponse(
          response,
          HTTPStatus.BAD_REQUEST,
          `Failed to parse body of request: ${err.message}`
        )
        return
      }

      for (const path of this.sortedPostPaths) {
        if (request.url!.startsWith(path)) {
          this.postPaths.get(path)!(
            (request as any).body,
            { headers: request.headers as Dictionary, url: request.url! },
            this.sendResponse.bind(this, response)
          )
          return
        }
      }
      this.terminateResponse(response, HTTPStatus.NOT_FOUND, 'Endpoint not found.')
github zenprotocol / explorer / server / components / api / oracle / oracleController.js View on Github external
proof: async function(req, res) {
    const { date, ticker } = req.query;
    if (!date || !ticker) {
      throw new HttpError(httpStatus.BAD_REQUEST, 'Both date and ticker must be supplied');
    }
    const data = await service.oracle.proof(ticker, date);
    res.status(httpStatus.OK).json(jsonResponse.create(httpStatus.OK, data));
  },
  lastUpdated: async function(req, res) {
github WaftTech / WaftEngine / server / modules / holidaylist / holidayValidation.js View on Github external
},
      ],
    },
    {
      field: 'isHalfDay',
      validate: [
        {
          condition: 'IsEmpty',
          msg: holidayConfig.validationMessage.isHalfDayRequired,
        },
      ],
    },
  ]);

  if (!isEmpty(errors)) {
    return otherHelper.sendResponse(res, HttpStatus.BAD_REQUEST, false, null, errors, 'Validation Error.', null);
  } else {
    return next();
  }
};