Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('decorates toolkit with #boomify throwing a Boom#boomify error', () => {
const error = new Error('test error')
const options = {
statusCode: 400,
message: testErrorMessage,
decorate: testErrorData,
override: false
}
const expectedBoomError = Boom.boomify(error, options)
try {
toolkit.boomify(error, options)
} catch (err) {
expect(err).to.deep.include(expectedBoomError)
return
}
throw new Error(`Didn't throw a Boom#boomify error`)
})
function handleHttpError(ctx, error) {
let parsedError;
if (error.name === 'BadRequestError') {
parsedError = Boom.badData(error.message);
} else {
parsedError = Boom.boomify(error);
}
const { statusCode, payload } = parsedError.output;
ctx.response.status = statusCode;
ctx.response.body = payload || {};
ctx.app.emit('error', error, ctx);
}
handler: async (request, h) => {
try {
const loggedInUser = request.auth && request.auth.credentials
const controller = new route.Controller({ admin }, loggedInUser)
const ret = await controller[route.action](request, h)
return ret
} catch (e) {
console.log(e)
throw Boom.boomify(e)
}
},
})
function handleError(exportType, err) {
if (err instanceof esErrors['401']) return boom.unauthorized(`Sorry, you aren't authenticated`);
if (err instanceof esErrors['403']) return boom.forbidden(`Sorry, you are not authorized to create ${exportType} reports`);
if (err instanceof esErrors['404']) return boom.boomify(err, { statusCode: 404 });
return err;
}
}
exports.create = async function (request, h) {
try {
Sidecar.logRequest(request)
const entity = await Participant.getByName(request.payload.name)
handleExistingRecord(entity)
const participant = await Participant.create(request.payload)
return h.response(buildResponse(participant)).code(201)
} catch (err) {
throw Boom.boomify(err, {statusCode: 400, message: 'An error has occurred'})
}
}
export async function callEsSearchApi({ callCluster, index, body, queryParams }) {
try {
return {
ok: true,
resp: await callCluster('search', {
...queryParams,
index,
body,
}),
};
} catch (error) {
throw Boom.boomify(error, { statusCode: error.statusCode || 500 });
}
}
this._stop = function (err) {
if (!self.aborted) {
self.aborted = true;
if (self.onAbort) {
self.onAbort(err ? Boom.boomify(err) : new Boom('Job aborted'));
}
}
};
.catch(err => {
if (err.status) {
return next(new Boom('Identity Not Verified', {statusCode: err.status, data: err}));
}
if (Boom.isBoom(err)) {
return next(err);
}
return next(Boom.boomify(err));
});
} else {
.catch(err => reply(boom.boomify(err)));
}
.catch(err => reply(boom.boomify(err)));
},