How to use the boom.badData 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 brave / vault / src / controllers / helper.js View on Github external
exports.verify = async function (debug, user, data) {
  var combo, diff, hash, nonce, r, s, signature
  var header = data.header
  var payload = data.payload

  var u8 = function (a) { return new Uint8Array(a) }

  if (!user.version) {
    if (header) return boom.badData('user entry is not cryptographically-enabled')

    return null    // no user entry credentials, no data signature
  }

  if (!header) return boom.badRequest('payload is not cryptographically-signed')

  if (user.version !== 1) {
    return boom.badRequest('unknown user entry cryptography version: ' + JSON.stringify(user.version))
  }

  nonce = header.nonce
  if (typeof nonce === 'string') nonce = parseFloat(nonce)
  if (isNaN(nonce)) return boom.badRequest('header.nonce is invalid: ' + JSON.stringify(header.nonce))
  diff = Math.abs(underscore.now() - (nonce * 1000.0))
  // NB: 10 minutes is temporary
  if (diff > (10 * 60 * 1000)) return boom.badData('header.nonce is untimely: ' + JSON.stringify(header.nonce))
github brave / vault / src / controllers / sync.js View on Github external
var timestamp = request.payload.timestamp
    var appStates = runtime.db.get('app_states')

    state = { $currentDate: { timestamp: { $type: 'timestamp' } },
              $set: { userId: userId,
                      payload: request.payload.payload
                    }
            }
    if (timestamp) {
      try { timestamp = bson.Timestamp.fromString(timestamp) } catch (ex) {
        return reply(boom.badRequest('invalid timestamp: ' + timestamp))
      }

      count = await appStates.update({ userId: userId, timestamp: timestamp }, state, { upsert: false })
      if (typeof count === 'object') { count = count.nMatched }
      if (count === 0) { return reply(boom.badData('timestamp mismatch: ' + timestamp)) }
    } else {
      await appStates.update({ userId: userId }, state, { upsert: true })
    }

    result = await appStates.findOne({ userId: userId }, { timestamp: true })
    underscore.extend(result, { timestamp: result.timestamp.toString() })
    reply(underscore.omit(result, '_id', 'userId'))
  }
},
github brave / ledger / src / controllers / address.js View on Github external
var debug = braveHapi.debug(module, request)
    var address = request.params.address
    var actor = request.payload.actor
    var amount = request.payload.amount
    var currency = request.payload.currency
    var fee = request.payload.fee
    var populates = runtime.db.get('populates', debug)
    var transactionId = request.payload.transactionId
    var wallets = runtime.db.get('wallets', debug)

    wallet = await wallets.findOne({ address: address })
    if (!wallet) return reply(boom.notFound('invalid address: ' + address))

    try {
      result = await compareCharge(debug, actor, transactionId, amount, currency)
      if (result) return reply(boom.badData(result))
    } catch (ex) {
      runtime.notify(debug, { text: 'retrieve error: ' + ex.toString() })
      debug('retrieve', ex)
      return boom.badGateway(ex.toString())
    }
    if (amount <= fee) return reply(boom.badData('amount/fee mismatch'))

    rate = runtime.wallet.rates[currency.toUpperCase()]
    satoshis = Math.round((amount / rate) * 1e8)

    state = {
      $currentDate: { timestamp: { $type: 'timestamp' } },
      $set: underscore.extends({ paymentId: wallet.paymentId, satoshis: satoshis },
                               underscore.omit(request.payload, [ 'transactionId' ]))
    }
    await populates.update({ address: address, transactionId: transactionId }, state, { upsert: true })
github tanepiper / node-gitio / lib / gitio.js View on Github external
return new Promise((resolve, reject) => {

    address = address.replace(/^http:\/\//i, 'https://');

    if (!URL_REGEX.test(address)) {
      return reject(Boom.badData('The url ' + address + ' is not a valid address for git.io'));
    }

    const body = 'url=' + address + (code ? '&code=' + code : '');
    const req = request(
      Object.assign(
        {},
        REQUEST_CONFIG,
        { headers: { 'content-length': body.length } }
      ), (response) => {

        if (response.statusCode >= 400) {
          return reject(Boom.create(response.statusCode, response.statusMessage, response));
        }

        const output = [];
github brave / vault / src / controllers / ad-manifest.js View on Github external
return async function (request, reply) {
    var result
    var debug = braveHapi.debug(module, request)
    var payload = request.payload
    var hostname = payload.hostname
    var siteInfo = runtime.db.get('site_info')

    try {
      await siteInfo.insert(underscore.extend(payload, { timestamp: bson.Timestamp() }))
    } catch (ex) {
      debug('insert failed for siteInfo', ex)
      return reply(boom.badData('ad-manifest entry already exists: ' + hostname))
    }

    result = await siteInfo.findOne({ hostname: hostname })
    if (!result) { return reply(boom.badImplementation('database creation failed: ' + hostname)) }
    result = underscore.extend(underscore.omit(result, '_id', 'timestamp'), { timestamp: result.timestamp.toString() })

    reply(result)
  }
},
github AMPATH / etl-rest-server / dao / eid / etl-eid-dao.js View on Github external
.catch(function (error) {
                                  reject(error);
                                  callback(Boom.badData(error.message));
                              })
                      });
github ArkEcosystem / core / packages / core-json-rpc / src / server / methods / transactions / broadcast.ts View on Github external
async method(params) {
        const transaction = await database.get(params.id);

        if (!transaction) {
            return Boom.notFound(`Transaction ${params.id} could not be found.`);
        }

        if (!crypto.verify(transaction)) {
            return Boom.badData();
        }

        await network.sendPOST("transactions", {
            transactions: [transaction],
        });

        return transaction;
    },
    schema: {
github roblav96 / robinhood.tools / src / server / api / polka.request.ts View on Github external
req.onend = function onend() {
		req.ondata = _.noop; req.onend = _.noop
		let body = chunks.join('')
		if (!body) return next();
		let content = req.headers['content-type']
		if (content == 'application/json') {
			let parsed = fastjsonparse(body)
			if (parsed.err) return next(boom.badData(parsed.err.message));
			req.body = parsed.value
		} else if (content == 'application/x-www-form-urlencoded') {
			req.body = qs.parse(body)
		} else {
			req.body = body
		}
		next()
	}
github brave-intl / bat-ledger / eyeshade / controllers / accounts.js View on Github external
return async (request, h) => {
    let { type } = request.params
    let {
      order,
      limit
    } = request.query

    if (type === 'contributions') {
      type = 'contribution'
    } else if (type === 'referrals') {
      type = 'referral'
    } else {
      throw boom.badData('type must be contributions or referrals')
    }

    const query1 = queries.earnings({
      asc: order === 'asc'
    })

    const { rows } = await runtime.postgres.query(query1, [type, limit])
    return rows
  }
},
github brave-intl / bat-ledger / ledger / controllers / grants.js View on Github external
return async (request, h) => {
    const debug = braveHapi.debug(module, request)
    const wallets = runtime.database.get('wallets', debug)

    let payload = request.payload

    if (payload.file) {
      payload = payload.file
      const validity = cohortsAssignmentSchema.validate(payload)
      if (validity.error) {
        throw boom.badData(validity.error)
      }
    }

    for (let entry of payload) {
      await wallets.update({ 'paymentId': entry.paymentId }, { $set: { 'cohort': entry.cohort } })
    }

    return {}
  }
},