How to use http-assert - 3 common examples

To help you get started, we’ve selected a few http-assert 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 sofish / sofi.sh / server / store.js View on Github external
switch (true) {
    // required
    case schema[key].required && !obj.hasOwnProperty(key):
      httpAssert(false, 500, `\`${key}\` is required`);

    // check type
    case obj.hasOwnProperty(key) && !Helper.compareType(schema[key].type(), obj[key]):
      httpAssert(false, 500, `\`${key}\` should be a ${Helper.is(schema[key].type())}`);

    // check length
    case obj.hasOwnProperty(key) && schema[key].length:
      checkLength(obj[key], schema[key].length, key);

    // check pattern
    case obj.hasOwnProperty(key) && schema[key].pattern:
      httpAssert(schema[key].pattern.test(obj[key]), 500, schema[key].message || `\`${key}\` is not valid`);

    // default value
    case !obj.hasOwnProperty(key) && schema[key].hasOwnProperty('default'):
      obj[key] = schema[key].default;
  }

  return {key: key, value: obj[key]};
}
github sofish / sofi.sh / server / store.js View on Github external
export function validSchema(key, obj, schema) {
  // ignore
  if(!schema.hasOwnProperty(key)) return null;

  switch (true) {
    // required
    case schema[key].required && !obj.hasOwnProperty(key):
      httpAssert(false, 500, `\`${key}\` is required`);

    // check type
    case obj.hasOwnProperty(key) && !Helper.compareType(schema[key].type(), obj[key]):
      httpAssert(false, 500, `\`${key}\` should be a ${Helper.is(schema[key].type())}`);

    // check length
    case obj.hasOwnProperty(key) && schema[key].length:
      checkLength(obj[key], schema[key].length, key);

    // check pattern
    case obj.hasOwnProperty(key) && schema[key].pattern:
      httpAssert(schema[key].pattern.test(obj[key]), 500, schema[key].message || `\`${key}\` is not valid`);

    // default value
    case !obj.hasOwnProperty(key) && schema[key].hasOwnProperty('default'):
      obj[key] = schema[key].default;
github sofish / sofi.sh / server / store.js View on Github external
export function collection(ctx, collectionName) {
  var db = ctx.app.context.db;
  httpAssert(db, 503);
  return db.collection(collectionName);
};

http-assert

assert with status codes

MIT
Latest version published 3 years ago

Package Health Score

73 / 100
Full package analysis

Popular http-assert functions