How to use the boom.notAcceptable 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 elastic / kibana / src / plugins / share / server / routes / lib / short_url_assert_valid.ts View on Github external
export function shortUrlAssertValid(url: string) {
  const { protocol, hostname, pathname } = parse(url);

  if (protocol) {
    throw Boom.notAcceptable(`Short url targets cannot have a protocol, found "${protocol}"`);
  }

  if (hostname) {
    throw Boom.notAcceptable(`Short url targets cannot have a hostname, found "${hostname}"`);
  }

  const pathnameParts = trim(pathname, '/').split('/');
  if (pathnameParts.length !== 2) {
    throw Boom.notAcceptable(
      `Short url target path must be in the format "/app/{{appId}}", found "${pathname}"`
    );
  }
}
github roblav96 / robinhood.tools / src / server / api / quotes.api.ts View on Github external
async handler(req, res) {
		let allrkeys = Object.keys(quotes.ALL_RKEYS)
		let symbols = req.body.symbols as string[]
		let types = (req.body.types || allrkeys) as Quotes.AllKeys[]

		let invalids = _.difference(types, allrkeys)
		if (invalids.length > 0) throw boom.notAcceptable(invalids.toString(), { invalids });

		return quotes.getAlls(symbols, types)
	}
})
github elastic / kibana / src / server / saved_objects / service / lib / search_dsl / search_dsl.js View on Github external
export function getSearchDsl(mappings, schema, options = {}) {
  const {
    type,
    search,
    searchFields,
    sortField,
    sortOrder,
    namespace,
  } = options;

  if (!type) {
    throw Boom.notAcceptable('type must be specified');
  }

  if (sortOrder && !sortField) {
    throw Boom.notAcceptable('sortOrder requires a sortField');
  }

  return {
    ...getQueryParams(mappings, schema, namespace, type, search, searchFields),
    ...getSortingParams(mappings, type, sortField, sortOrder),
  };
}
github ezpaarse-project / ezpaarse / routes / admin.js View on Github external
function (req, res, next) {
    var gitScript = path.join(__dirname, '../bin/git-status');
    var directory;

    switch (req.params.repo) {
    case 'platforms':
    case 'resources':
    case 'middlewares':
      directory = path.join(__dirname, '..', req.params.repo);
      break;
    case 'app':
      directory = path.join(__dirname, '..');
      break;
    default:
      return next(Boom.notAcceptable('invalid_repository'));
    }

    execFile(gitScript, { cwd: directory }, function (error, stdout) {
      if (error) { return next(error); }
      if (!stdout) { return next(Boom.badImplementation()); }

      try {
        var result = JSON.parse(stdout);
        res.status(200).json(result);
      } catch (e) {
        return next(e);
      }
    });
  }
);
github danactive / history / api / server / plugins / album / lib / json.js View on Github external
function safePath(name, value) {
  const restriction = () => `Valid ${name} contains Alpha-Numeric characters, is at least 1 character long but less than 25,
    and may contain any special characters including dash (-) or underscore (_)`;

  if (!value || validation[name].validate(value).error) {
    return boom.notAcceptable(restriction());
  }

  if (name === 'albumStem') {
    return `album_${value}.xml`;
  }

  return `gallery-${value}`;
}
github tableflip / guvnor / lib / daemon / routes / processes / name / patch.js View on Github external
const updateProcess = (request, reply) => {
  if (request.payload.status === 'start') {
    return request.server.methods.startProcess(context(request), request.params.name)
  } else if (request.payload.status === 'stop') {
    return request.server.methods.stopProcess(context(request), request.params.name)
  }

  if (request.payload.workers) {
    return request.server.methods.setNumWorkers(context(request), request.params.name, request.payload.workers)
  }

  return Promise.reject(Boom.notAcceptable('A status or some workers should be sent'))
}
github ArkEcosystem / core / packages / core-p2p / lib / server / versions / peer / handlers / transactions.js View on Github external
async handler(request, h) {
    const guard = new TransactionGuard(transactionPool)

    const result = await guard.validate(request.payload.transactions)

    if (result.invalid.length > 0) {
      return Boom.notAcceptable(
        'Transactions list could not be accepted.',
        guard.errors,
      )
    }

    if (result.broadcast.length > 0) {
      container.resolvePlugin('p2p').broadcastTransactions(result.broadcast)
    }

    return { data: result.accept.map(t => t.id) }
  },
  config: {
github sinfo / cannon-api / server / resources / redeem.js View on Github external
function use (redeem, userId, cb) {
  if (redeem === null) {
    log.error({err: err, redeem: redeem.id}, 'redeem code not found')
    return cb(Boom.notAcceptable())
  }

  if (redeem.achievement === null) {
    log.error({err: err, achievement: redeem.achievement}, 'achievement of redeem not found')
    return cb(Boom.notAcceptable())
  }

  if (redeem.available !== undefined && redeem.available <= 0) {
    log.info({err: err, user: userId, redeem: redeem.id}, 'redeem code not available anymore')
    return cb(Boom.notAcceptable())
  }

  Achievement.findOne({ id: redeem.achievement }, (err, achievement) => {
    if (err) {
      log.error({err: err, achievement: achievement.id}, 'achievement of redeem not found')
      return cb(Boom.notAcceptable())
    }

    let now = new Date().getTime()
    
    if (achievement.validity !== undefined
github tableflip / guvnor / lib / daemon / routes / processes / name / events / post.js View on Github external
request.log([DEBUG, CONTEXT], `${request.params.name} emitted ${request.payload.event} with args ${JSON.stringify(request.payload.args)}`)

    return receiveEvent(request, request.params.name, request.payload.event, request.payload.args)
  } else if (request.auth.credentials.scope.indexOf('user') !== -1) {
    request.log([DEBUG, CONTEXT], `Sending ${request.payload.event} to ${request.params.name} with args ${JSON.stringify(request.payload.args)}`)

    return request.server.methods.sendEvent(
      context(request),
      request.params.name,
      request.payload.event,
      request.payload.args,
      request.payload.worker
    )
  }

  return Promise.reject(Boom.notAcceptable('An event should be sent by or to a process'))
}