How to use the http-errors.NotFound function in http-errors

To help you get started, we’ve selected a few http-errors 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 windycom / git-deploy / src / lib / index.js View on Github external
const requestHandler = (checkRequest, parseRequest) => async (req, res, next) => {
	const args = checkRequest(req);
	if (!args) {
		next(new createError.NotFound());
		return;
	}
	let deployment = null;
	try {
		deployment = await parseRequest(req.body, ...args);
		if (!deployment) {
			// Don't treat this as error. This simply means: We ignore the request.
			res.status(201).end();
			return;
		}
		// Finish request first
		res.status(200).send('Deployment scheduled.');
	} catch (error) {
		console.error(error.message);
		res.status(error.statusCode || 500).send({
			error: error.message,
github strongloop / loopback-next / packages / rest / src / router / external-express-routes.ts View on Github external
let handled = await executeRequestHandler(
      this._externalRouter,
      request,
      response,
    );
    if (handled) return;

    handled = await executeRequestHandler(
      this._staticAssets,
      request,
      response,
    );
    if (handled) return;

    // Express router called next, which means no route was matched
    throw new HttpErrors.NotFound(
      `Endpoint "${request.method} ${request.path}" not found.`,
    );
  }
github strongloop / loopback-next / packages / rest / src / router / external-express-routes.ts View on Github external
let handled = await executeRequestHandler(
      this._externalRouter,
      request,
      response,
    );
    if (handled) return;

    handled = await executeRequestHandler(
      this._staticAssets,
      request,
      response,
    );
    if (handled) return;

    // Express router called next, which means no route was matched
    throw new HttpErrors.NotFound(
      `Endpoint "${request.method} ${request.path}" not found.`,
    );
  }
github eosdac / eosdac-api / api-handlers / getProfile.js View on Github external
}, async (request, reply) => {
        const profile = await getProfile(fastify, request);
        if (profile) {
            reply.send(profile);
        } else {
            throw new NotFound('Account profile not found')
        }
    });
    next()
github stalniy / casl-express-example / src / modules / users / service.js View on Github external
async function update(req, res) {
  const user = await User.findById(req.params.id);

  if (!user) {
    throw new NotFound('User is not found');
  }

  user.set(req.body.user);
  req.ability.throwUnlessCan('update', user);
  await user.save();

  res.send({ user });
}
github medibloc / explorer / server / src / transaction / controller.js View on Github external
export const get = async (req, res) => {
  const { id } = req.params;
  const transaction = await Transaction.findByPk(id);
  if (!transaction) {
    throw new NotFound('transaction not exists');
  }
  res.json({ transaction });
};
github windycom / git-deploy / src / service / dashboard.js View on Github external
	router.use('*', (req, res, next) => { next(new createError.NotFound()); });
github lifechurch / melos / elaphros / plugins / bible / bible-reference.js View on Github external
module.exports = function bibleReference(req, reply) {
  const { isVerse, isChapter } = isVerseOrChapter(req.params.usfm)
  if (isChapter) {
    return bibleChapter(req, reply)
  } else if (isVerse) {
    return bibleVerse(req, reply)
  } else {
    if (reply.newrelic) {
      reply.newrelic.setTransactionName('not-found-bible')
    }
    const message = 'Invalid Bible reference: Neither Chapter nor Verse.'
    reply.captureException(new Error(message), `${message} [ ${req.params.usfm} ]`, { tags: { usfm: req.params.usfm } })
    return reply.send(new httpErrors.NotFound())
  }
}
github cablelabs / lpwanserver / rest / models / dao / production / networkProvisioningFields.js View on Github external
db.fetchRecord('networkProvisioningFields', 'id', id, function (err, rec) {
      if (err) {
        reject(err)
      }
      else if (!rec) {
        reject(new httpError.NotFound())
      }
      else {
        resolve(rec)
      }
    })
  })
github ShieldBattery / ShieldBattery / server / lib / wsapi / matchmaking.js View on Github external
async accept(data, next) {
    const client = this.getClient(data)
    if (!this.acceptor.registerAccept(client)) {
      throw new errors.NotFound('no active match found')
    }
  }