How to use the boom.boomify function in boom

To help you get started, we’ve selected a few boom 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 brainsiq / hapi-boom-decorators / tests / unit / decorators.js View on Github external
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`)
  })
github SokratisVidros / apicco / generator / templates / app / support / handleHttpError.js View on Github external
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);
}
github SoftwareBrothers / admin-bro / admin / integrations / hapi.js View on Github external
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)
          }
        },
      })
github elastic / kibana / x-pack / plugins / reporting / server / routes / main.js View on Github external
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;
  }
}
github mojaloop / central-ledger / src / api / participants / handler.js View on Github external
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'})
  }
}
github elastic / kibana / x-pack / legacy / plugins / graph / server / lib / es / call_es_search_api.js View on Github external
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 });
  }
}
github ezpaarse-project / ezpaarse / lib / job.js View on Github external
this._stop = function (err) {
    if (!self.aborted) {
      self.aborted = true;
      if (self.onAbort) {
        self.onAbort(err ? Boom.boomify(err) : new Boom('Job aborted'));
      }
    }
  };
github oddnetworks / oddworks / lib / middleware / request-verify.js View on Github external
.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 {