How to use the boom.badRequest 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 snyk / snyk / test / fixtures / qs-package / node_modules / hawk / lib / server.js View on Github external
request.method !== 'HEAD') {

        return callback(Boom.unauthorized('Invalid method', 'Hawk'));
    }

    // No other authentication

    if (request.authorization) {
        return callback(Boom.badRequest('Multiple authentications'));
    }

    // Parse bewit

    var bewitString = Hoek.base64urlDecode(resource[3]);
    if (bewitString instanceof Error) {
        return callback(Boom.badRequest('Invalid bewit encoding'));
    }

    // Bewit format: id\exp\mac\ext ('\' is used because it is a reserved header attribute character)

    var bewitParts = bewitString.split('\\');
    if (bewitParts.length !== 4) {
        return callback(Boom.badRequest('Invalid bewit structure'));
    }

    var bewit = {
        id: bewitParts[0],
        exp: parseInt(bewitParts[1], 10),
        mac: bewitParts[2],
        ext: bewitParts[3] || ''
    };
github developmentseed / macrocosm / routes / map.js View on Github external
function mapHandler (req, res) {
  // parse and validate bbox parameter from query
  // See services/BoundingBox.js.
  var paramString = req.query.bbox || '';
  var bbox = new BoundingBox.fromCoordinates(paramString.split(','));
  if (bbox.error) {
    return res(Boom.badRequest(bbox.error));
  }

  queryBbox(knex, bbox)
  .then(function(result) {
    var xmlDoc = XML.write({
      bbox: bbox,
      nodes: result.nodes,
      ways: result.ways,
      relations: result.relations
    });
    var response = res(xmlDoc.toString());
    response.type('text/xml');
  })
  .catch(function (err) {
    return res(Boom.wrap(err));
  });
github aya-experience / citation / citation-server / src / hapi-graphql / index.js View on Github external
if (showGraphiQL) {
			return null;
		}
		throw Boom.badRequest('Must provide query string.');
	}

	// GraphQL source.
	const source = new Source(query, 'GraphQL request');

	// Parse source to AST, reporting any syntax error.
	let documentAST;
	try {
		documentAST = parse(source);
	} catch (syntaxError) {
		// Return 400: Bad Request if any syntax errors errors exist.
		throw Boom.badRequest('Syntax error', [syntaxError]);
	}

	// Validate AST, reporting any errors.
	const validationErrors = validate(schema, documentAST, validationRules);
	if (validationErrors.length > 0) {
		// Return 400: Bad Request if any validation errors exist.
		throw Boom.badRequest('Validation error', validationErrors);
	}

	// Only query operations are allowed on GET requests.
	if (request.method === 'get') {
		// Determine if this GET request will perform a non-query.
		const operationAST = getOperationAST(documentAST, operationName);
		if (operationAST && operationAST.operation !== 'query') {
			// If GraphiQL can be shown, do not perform this query, but
			// provide it to GraphiQL so that the requester may perform it
github epochtalk / epochtalk / modules / ept-images / routes / localUpload.js View on Github external
// make sure image file exists
      var file = request.payload.file;
      if (!file) { return reply(Boom.badRequest('No File Attached')); }

      // decode policy
      var policyPayload = request.payload.policy;
      var decipher = crypto.createDecipher('aes-256-ctr', config.privateKey);
      var decoded = decipher.update(policyPayload,'hex','utf8');
      decoded += decipher.final('utf8');

      // parse policy
      var policy;
      try { policy = JSON.parse(decoded); }
      catch(e) { return reply(Boom.badRequest('Malformed Policy')); }
      if (!policy) { return reply(Boom.badRequest('Malformed Policy')); }

      // check filename
      var filename = policy.filename;
      if (!filename) { return reply(Boom.badRequest('Invalid Policy')); }

      // check policy expiration
      var expiration = new Date(policy.expiration);
      if (expiration < Date.now()) {
        return reply(Boom.badRequest('Policy Timed Out'));
      }

      request.imageStore.uploadImage(file, filename, reply);
    }
  };
github JKHeadley / rest-hapi / api / utilities_sequelize / handler-helper-factory.js View on Github external
}).catch(function (error) {
          Log.error("error: ", JSON.stringify(error));
          return reply(Boom.badRequest("There was a preprocessing error creating the resource", error));
        });
      }
github wiljanslofstra / pdf-server / lib / screenshot.js View on Github external
const urlObj = url.parse(options.url);

    const browser = await puppeteer.launch({
        args: ['--no-sandbox', '--disable-setuid-sandbox'],
    });

    const page = await browser.newPage();

    await page.emulateMedia((typeof options.emulateMedia !== 'undefined') ? options.emulateMedia : 'screen');

    if (typeof options.viewport !== 'undefined') {
        const { width, height } = options.viewport;

        if (isNaN(width) || isNaN(height)) {
            return reply(Boom.badRequest('width or height for the viewport are not numerical'));
        }

        await page.setViewport({
            width: parseInt(width, 10),
            height: parseInt(height, 10),
        });
    }

    const filePath = uniqueFilename(`screenshots/${encodeURIComponent(urlObj.host)}.png`);

    await page.goto(options.url);
    await page.screenshot({
        path: path.resolve(global.BASE_PATH, filePath),
        omitBackground: false,
    });
github hapi-learning / hapi-learning / app / utils / error.js View on Github external
server.decorate('reply', 'badRequest', function (message) {

        return this.response(Boom.badRequest(message || 'Bad request'));
    });
github epochtalk / epochtalk / modules / ept-threads / authorization / purge.js View on Github external
method: server.db.moderators.isModeratorWithThreadId,
      args: [userId, threadId],
      permission: server.plugins.acls.getACLValue(auth, 'threads.purge.bypass.owner.mod')
    },
    {
      type: 'runValidation',
      method: function(server, auth, acl, threadId) {
        return server.db.threads.getThreadFirstPost(threadId)
        .then(function(post) {
          return server.methods.common.posts.hasPriority(server, auth, acl, post.id);
        });
      },
      args: [server, auth, 'threads.purge.bypass.owner.priority', threadId]
    }
  ];
  var purgeLevel = server.authorization.stitch(Boom.badRequest(), conditions, 'any');

  var notBannedFromBoard = server.authorization.common.isNotBannedFromBoard(Boom.forbidden('You are banned from this board'), server, userId, { threadId: threadId });

  return Promise.all([allowed, read, write, active, purgeLevel, notBannedFromBoard]);
};
github mojaloop / central-ledger / src / admin / routing / handler.js View on Github external
let routes = config['MOJA_HUB_NAME'] === 'Blue Moja' ? routesBlueMoja : routesRedMoja
    let routeTable = new PrefixMap()
    routes.forEach(route => {
      routeTable.insert(route.address, route)
    })

    const finalDestination = request.headers['fspiop-final-destination'] ? request.headers['fspiop-final-destination'] : request.headers['fspiop-destination']
    const route = routeTable.resolve(finalDestination)
    if (!route) throw new Error('Cannot resolve route for ' + finalDestination)

    return {
      finalDestination: finalDestination,
      destination: route.nextHop
    }
  } catch (err) {
    throw Boom.badRequest(err.message)
  }
}
github superchargejs / framework / app / models / user.js View on Github external
async comparePasswordResetToken (resetToken) {
    if (this.passwordResetDeadline < Date.now()) {
      throw Boom.badRequest('Your password reset token is invalid, please request a new one.')
    }

    const isMatch = await Hash.check(resetToken, this.passwordResetToken)

    if (isMatch) {
      return this
    }

    const message = 'Your password reset token is invalid, please request a new one.'
    throw Boom.badRequest(message, { resetToken: message })
  }