How to use the http-status.OK 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 box / box-node-sdk / lib / token-manager.js View on Github external
.then(response => {

				// Response Error: The API is telling us that we attempted an invalid token grant. This
				// means that our refresh token or auth code has exipred, so propagate an "Expired Tokens"
				// error.
				if (response.body && response.body.error && response.body.error === 'invalid_grant') {
					var errDescription = response.body.error_description;
					var message = errDescription ? `Auth Error: ${errDescription}` : undefined;
					throw errors.buildAuthError(response, message);
				}

				// Unexpected Response: If the token request couldn't get a valid response, then we're
				// out of options. Build an "Unexpected Response" error and propagate it out for the
				// consumer to handle.
				if (response.statusCode !== httpStatusCodes.OK || response.body instanceof Buffer) {
					throw errors.buildUnexpectedResponseError(response);
				}

				// Check to see if token response is valid in case the API returns us a 200 with a malformed token
				if (!isValidTokenResponse(formParams.grant_type, response.body)) {
					throw errors.buildResponseError(response, 'Token format from response invalid');
				}

				// Got valid token response. Parse out the TokenInfo and propagate it back.
				return getTokensFromGrantResponse(response.body);
			});
	},
github shortlist-digital / tapestry-wp / src / server / handle-dynamic.js View on Github external
async (err, asyncProps) => {
              // 500 if error from AsyncProps
              if (err) {
                log.error({ err })
                return reply(err, HTTPStatus.INTERNAL_SERVER_ERROR)
              }

              const response = handleApiResponse(
                idx(asyncProps, _ => _.propsArray[0].data),
                renderProps.routes[1]
              )

              const status = idx(response, _ => _.code)
                ? response.code
                : HTTPStatus.OK

              const cacheKey = normaliseUrlPath(request.url.pathname)

              // Find HTML based on path - might be undefined
              const cachedHTML = await cache.get(cacheKey)
              log.debug(
                `Cache contains ${chalk.green(cacheKey)} in html: ${Boolean(
                  cachedHTML
                )}`
              )

              // respond with HTML from cache if not undefined
              if (cachedHTML && isPreview) {
                log.silly(
                  `HTML is in cache but skipped for preview ${chalk.green(
                    cacheKey
github restberry / restberry / test / tree-branch / libs / testlib.js View on Github external
}, function(err, res, json) {
        if (res.statusCode === httpStatus.OK) {
            testlib.session.start(res);
            exports.client = testlib.client;
            next(json.user.id);
        }
    });
};
github deepstreamIO / deepstream.io / src / connection-endpoint / http / node-server.ts View on Github external
private handleGet (
    request: http.IncomingMessage,
    response: http.ServerResponse
   ): void {
    const parsedUrl = url.parse(request.url as string, true)
    const onResponse = Server.onHandlerResponse.bind(null, response)

    if (parsedUrl.pathname === this.config.healthCheckPath) {
      response.setHeader('Content-Type', 'text/plain; charset=utf-8')
      response.writeHead(HTTPStatus.OK)
      response.end('OK\r\n\r\n')

    } else if (this.getPathRegExp.test(parsedUrl.pathname as string)) {
      this.httpEvents.onGetMessage(parsedUrl.query, request.headers, onResponse)

    } else {
      Server.terminateResponse(response, HTTPStatus.NOT_FOUND, 'Endpoint not found.')
    }
  }
github WaftTech / WaftEngine / server / modules / user / userController.js View on Github external
.split('\\')
          .join('/')
          .split('server/')[1] + '/';
      req.file.path = req.file.path
        .split('\\')
        .join('/')
        .split('server/')[1];
      newdatas.image = req.file;
    }

    const updateUser = await users.findByIdAndUpdate(id, { $set: newdatas });
    const msg = 'User Update Success';
    const msgfail = 'User not found';

    if (updateUser) {
      return otherHelper.sendResponse(res, httpStatus.OK, true, req.body, null, msg, null);
    } else {
      return otherHelper.sendResponse(res, httpStatus.NOT_FOUND, false, null, null, msgfail, null);
    }
  } catch (err) {
    return next(err);
  }
};
github zenprotocol / explorer / server / components / api / contracts / contractsController.js View on Github external
index: async function(req, res) {
    const { page, pageSize, sorted } = req.query;
    const contracts = await contractsBLL.findAll({ page, pageSize, sorted });
    res.status(httpStatus.OK).json(jsonResponse.create(httpStatus.OK, contracts));
  },
  show: async function(req, res) {
github WaftTech / WaftEngine / server / modules / menu / menucontroller.js View on Github external
menuController.getMenu = async (req, res, next) => {
  let { page, size, populate, selectQuery, searchQuery, sortQuery } = otherHelper.parseFilters(req, 10, false);
  searchQuery = { is_deleted: false };
  if (req.query.find_title) {
    searchQuery = { title: { $regex: req.query.find_title, $options: 'i' }, ...searchQuery };
  }
  if (req.query.find_key) {
    searchQuery = { key: { $regex: req.query.find_key, $options: 'i' }, ...searchQuery };
  }

  selectQuery = 'title key order is_active';
  let data = await otherHelper.getquerySendResponse(menusch, page, size, sortQuery, searchQuery, selectQuery, next, populate);
  return otherHelper.paginationSendResponse(res, httpStatus.OK, true, data.data, 'Menu get success!!', page, size, data.totaldata);
};
github joshuaalpuerto / node-ddd-boilerplate / src / interfaces / http / modules / index.js View on Github external
router.get('/swagger.json', (req, res) => {
    res.status(Status.OK).json(swaggerSpec)
  })
github WaftTech / WaftEngine / server / modules / CreateLeave / CreateLeaveController.js View on Github external
CreateLeaveController.getData = async (req, res, next) => {
  let fiscalyear = req.params.fiscalid;
  let data = {};

  try {
    data.Employee = await UsersModel.find({ IsDeleted: false }, 'name gender');
    data.Leave = await LeaveTypeModel.find({ IsDeleted: false }, 'ApplicableGender LeaveName NoOfDays');
    data.AssignedLeave = await AssignedLeave.find({ IsDeleted: false, FiscalYear: fiscalyear }, 'LeaveType EmployeeId NoOfDays');
  } catch (err) {
    next(err);
  }
  return otherHelper.sendResponse(res, HttpStatus.OK, true, data, null, 'CreateLeave data delivered successfully!!!', null);
};
github talyssonoc / node-api-boilerplate / src / interfaces / http / user / UsersController.js View on Github external
.on(SUCCESS, (users) => {
        res
          .status(Status.OK)
          .json(users.map(userSerializer.serialize));
      })
      .on(ERROR, next);