Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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,
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.`,
);
}
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.`,
);
}
}, async (request, reply) => {
const profile = await getProfile(fastify, request);
if (profile) {
reply.send(profile);
} else {
throw new NotFound('Account profile not found')
}
});
next()
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 });
}
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 });
};
router.use('*', (req, res, next) => { next(new createError.NotFound()); });
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())
}
}
db.fetchRecord('networkProvisioningFields', 'id', id, function (err, rec) {
if (err) {
reject(err)
}
else if (!rec) {
reject(new httpError.NotFound())
}
else {
resolve(rec)
}
})
})
async accept(data, next) {
const client = this.getClient(data)
if (!this.acceptor.registerAccept(client)) {
throw new errors.NotFound('no active match found')
}
}