How to use the boom.wrap 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 TheScienceMuseum / collectionsonline / routes / plugins / error.js View on Github external
server.ext('onPreResponse', (request, reply) => {
    // Only interested in errors
    if (!(request.response instanceof Error)) return reply.continue();

    const error = Boom.wrap(request.response);
    const accept = request.headers.accept || '';

    if (error.output.statusCode >= 500) {
      console.error(error.stack);
    }

    if (accept.indexOf('text/html') === 0) {
      // Respond with an error template
      if (error.output.statusCode === 401) {
        return reply.redirect('/login');
      }

      if (error.output.statusCode === 404) {
        var data = {};
        data.footer = require('../../fixtures/footer');
        data.museums = require('../../fixtures/museums');
github devinivy / bedwetter / lib / actions / remove.js View on Github external
// Transform the original options using options hook
    var options = GeneralUtil.applyOptionsHook(request, origOptions);
    
    var RequestState = request.plugins.bedwetter = {
      action: 'remove',
      options: options
    };
    
    var actionUtil = require('../actionUtil')(request, options);
    
    // Ensure a model and alias can be deduced from the request.
    var Model = actionUtil.parseModel();
    var relation = options.associationAttr;
    
    if (!relation) {
      return reply(Boom.wrap(new Error('Missing required route option, `options.associationAttr`.')));
    }
  
    var associationAttr = _.findWhere(options.associations, { alias: relation });
    Hoek.assert(_.isObject(associationAttr), 'Bad association.');
  
    var ChildModel = request.model[associationAttr.collection];
    var childPkAttr = ChildModel.primaryKey;
  
    // The primary key of the parent record
    var parentPk;
    
    try {
      parentPk = actionUtil.requirePk();
    } catch(e) {
      return reply(Boom.wrap(e)); 
    }
github alanshaw / david-www / src / routes / api / info.js View on Github external
withManifestAndInfo(req, {peer: true}, (err, manifest, info) => {
      if (err) return next(Boom.wrap(err, 500, 'Failed to get manifest and info'))
      const payload = merge({manifest: minifyManifest(manifest), info}, projectData(req, 'peer'))
      res.json(payload)
    })
  })
github oddnetworks / oddworks / lib / catalog.js View on Github external
}, function (err, entities) {
			if (err) {
				return next(boom.wrap(err));
			}
			if (!entities) {
				return next(boom.notFound());
			}

			req.data = entities;

			done(null, req, res, next);
		});
	}
github nylas-mail-lives / nylas-mail / packages / client-sync / src / local-api / route-helpers.es6 View on Github external
export async function createAndReplyWithSyncbackRequest(request, reply, syncRequestArgs = {}) {
  try {
    const account = request.auth.credentials
    const {wakeSync = true} = syncRequestArgs
    syncRequestArgs.accountId = account.id

    const db = await request.getAccountDatabase()
    const syncbackRequest = await db.SyncbackRequest.create(syncRequestArgs)

    if (wakeSync) {
      wakeSyncWorker(account.id, `Need to run task ${syncbackRequest.type}`)
    }
    reply(Serialization.jsonStringify(syncbackRequest))
    return syncbackRequest
  } catch (err) {
    reply(Boom.wrap(err))
    return null
  }
}
github alanshaw / david-www / src / routes / session.js View on Github external
req.session.set('session/access-token', data.access_token, (err) => {
          if (err) return next(Boom.wrap(err, 500, 'Failed to store access token in session'))

          req.session.set('session/user', data.user, (err) => {
            if (err) return next(Boom.wrap(err, 500, 'Failed to store user in session'))
            res.redirect('/?success')
          })
        })
      })