How to use the http-errors.MethodNotAllowed function in http-errors

To help you get started, we’ve selected a few http-errors 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 woleet / woleet.id-server / server / src / api / routers / enrollment-create.ts View on Github external
router.post('/enrollment', validate.body('createEnrollment'), async function (ctx) {

  // Get enrollment to create from body
  const enrollment: ApiPostEnrollmentObject = ctx.request.body;

  // Verify all settings required for enrollment
  // TODO: change this method with an end point to send the mail
  if (!enrollment.test) {
    if (!getServerConfig().useSMTP) {
      throw new MethodNotAllowed('SMTP Server not configured.');
    }
    if (!getServerConfig().contact) {
      throw new MethodNotAllowed('Admin contact not configured.');
    }
    if (!getServerConfig().webClientURL) {
      throw new MethodNotAllowed('Web client URL not configured.');
    }
    if (!getServerConfig().proofDeskAPIIsValid) {
      throw new MethodNotAllowed('ProofDesk account not configurated.');
    }
  }

  // Create enrollment
  const created = await createEnrollment(enrollment);

  // Register enrollment creation event
github woleet / woleet.id-server / server / src / api / routers / enrollment-admin.ts View on Github external
router.post('/enrollment', validate.body('createEnrollment'), async function (ctx) {

  // Get enrollment to create from body
  const enrollment: ApiPostEnrollmentObject = ctx.request.body;

  // Verify all settings required for enrollment
  // TODO: change this method with an end point to send the mail
  if (!enrollment.test) {
    if (!getServerConfig().enableSMTP) {
      throw new MethodNotAllowed('SMTP Server not configured.');
    }
    if (!getServerConfig().contact) {
      throw new MethodNotAllowed('Admin contact not configured.');
    }
    if (!getServerConfig().webClientURL) {
      throw new MethodNotAllowed('Web client URL not configured.');
    }
    if (!getServerConfig().enableProofDesk) {
      throw new MethodNotAllowed('ProofDesk account not configured.');
    }
  }

  // Create enrollment
  const created = await createEnrollment(enrollment);

  // Register enrollment creation event
github woleet / woleet.id-server / server / src / api / routers / enrollment-admin.ts View on Github external
const enrollment: ApiPostEnrollmentObject = ctx.request.body;

  // Verify all settings required for enrollment
  // TODO: change this method with an end point to send the mail
  if (!enrollment.test) {
    if (!getServerConfig().enableSMTP) {
      throw new MethodNotAllowed('SMTP Server not configured.');
    }
    if (!getServerConfig().contact) {
      throw new MethodNotAllowed('Admin contact not configured.');
    }
    if (!getServerConfig().webClientURL) {
      throw new MethodNotAllowed('Web client URL not configured.');
    }
    if (!getServerConfig().enableProofDesk) {
      throw new MethodNotAllowed('ProofDesk account not configured.');
    }
  }

  // Create enrollment
  const created = await createEnrollment(enrollment);

  // Register enrollment creation event
  event.register({
    type: 'enrollment.create',
    authorizedUserId: ctx.session.user.get('id'),
    associatedTokenId: null,
    associatedUserId: created.userId,
    associatedKeyId: null,
    data: created.id
  });
github mcollina / fastify-gql / index.js View on Github external
throw err
        }
      }

      if (lru) {
        lru.set(source, { document, validationErrors, count: 1, jit: null })
      }
    } else {
      document = cached.document
    }

    if (reply && reply.request.raw.method === 'GET') {
      // let's validate we cannot do mutations here
      const operationAST = getOperationAST(document, operationName)
      if (operationAST.operation !== 'query') {
        const err = new MethodNotAllowed()
        err.errors = [new Error('Operation cannot be perfomed via a GET request')]
        throw err
      }
    }

    // minJit is 0 by default
    if (cached && cached.count++ === minJit) {
      cached.jit = compileQuery(schema, document, operationName)
    }

    if (cached && cached.jit !== null) {
      const res = await cached.jit.query(root, context, variables || {})
      return res
    }

    const execution = await execute(
github woleet / woleet.id-server / server / src / api / routers / enrollment-admin.ts View on Github external
router.post('/enrollment', validate.body('createEnrollment'), async function (ctx) {

  // Get enrollment to create from body
  const enrollment: ApiPostEnrollmentObject = ctx.request.body;

  // Verify all settings required for enrollment
  // TODO: change this method with an end point to send the mail
  if (!enrollment.test) {
    if (!getServerConfig().enableSMTP) {
      throw new MethodNotAllowed('SMTP Server not configured.');
    }
    if (!getServerConfig().contact) {
      throw new MethodNotAllowed('Admin contact not configured.');
    }
    if (!getServerConfig().webClientURL) {
      throw new MethodNotAllowed('Web client URL not configured.');
    }
    if (!getServerConfig().enableProofDesk) {
      throw new MethodNotAllowed('ProofDesk account not configured.');
    }
  }

  // Create enrollment
  const created = await createEnrollment(enrollment);

  // Register enrollment creation event
  event.register({
    type: 'enrollment.create',
    authorizedUserId: ctx.session.user.get('id'),
github koajs / router / lib / router.js View on Github external
} else {
            ctx.status = 501;
            ctx.set('Allow', allowedArr.join(', '));
          }
        } else if (allowedArr.length) {
          if (ctx.method === 'OPTIONS') {
            ctx.status = 200;
            ctx.body = '';
            ctx.set('Allow', allowedArr.join(', '));
          } else if (!allowed[ctx.method]) {
            if (options.throw) {
              var notAllowedThrowable;
              if (typeof options.methodNotAllowed === 'function') {
                notAllowedThrowable = options.methodNotAllowed(); // set whatever the user returns from their function
              } else {
                notAllowedThrowable = new HttpError.MethodNotAllowed();
              }
              throw notAllowedThrowable;
            } else {
              ctx.status = 405;
              ctx.set('Allow', allowedArr.join(', '));
            }
          }
        }
      }
    });
  };
github woleet / woleet.id-server / server / src / api / routers / enrollment-create.ts View on Github external
router.post('/enrollment', validate.body('createEnrollment'), async function (ctx) {

  // Get enrollment to create from body
  const enrollment: ApiPostEnrollmentObject = ctx.request.body;

  // Verify all settings required for enrollment
  // TODO: change this method with an end point to send the mail
  if (!enrollment.test) {
    if (!getServerConfig().useSMTP) {
      throw new MethodNotAllowed('SMTP Server not configured.');
    }
    if (!getServerConfig().contact) {
      throw new MethodNotAllowed('Admin contact not configured.');
    }
    if (!getServerConfig().webClientURL) {
      throw new MethodNotAllowed('Web client URL not configured.');
    }
    if (!getServerConfig().proofDeskAPIIsValid) {
      throw new MethodNotAllowed('ProofDesk account not configurated.');
    }
  }

  // Create enrollment
  const created = await createEnrollment(enrollment);

  // Register enrollment creation event
  event.register({
    type: 'enrollment.create',
    authorizedUserId: ctx.session.user.get('id'),
    associatedTokenId: null,
    associatedUserId: created.userId,
    associatedKeyId: null,
github woleet / woleet.id-server / server / src / api / routers / enrollment-create.ts View on Github external
router.post('/enrollment', validate.body('createEnrollment'), async function (ctx) {

  // Get enrollment to create from body
  const enrollment: ApiPostEnrollmentObject = ctx.request.body;

  // Verify all settings required for enrollment
  // TODO: change this method with an end point to send the mail
  if (!enrollment.test) {
    if (!getServerConfig().useSMTP) {
      throw new MethodNotAllowed('SMTP Server not configured.');
    }
    if (!getServerConfig().contact) {
      throw new MethodNotAllowed('Admin contact not configured.');
    }
    if (!getServerConfig().webClientURL) {
      throw new MethodNotAllowed('Web client URL not configured.');
    }
    if (!getServerConfig().proofDeskAPIIsValid) {
      throw new MethodNotAllowed('ProofDesk account not configurated.');
    }
  }

  // Create enrollment
  const created = await createEnrollment(enrollment);

  // Register enrollment creation event
  event.register({
    type: 'enrollment.create',
    authorizedUserId: ctx.session.user.get('id'),
github physiii / open-automation / node_modules / koa-router / lib / router.js View on Github external
} else {
            ctx.status = 501;
            ctx.set('Allow', allowedArr.join(', '));
          }
        } else if (allowedArr.length) {
          if (ctx.method === 'OPTIONS') {
            ctx.status = 200;
            ctx.body = '';
            ctx.set('Allow', allowedArr.join(', '));
          } else if (!allowed[ctx.method]) {
            if (options.throw) {
              var notAllowedThrowable;
              if (typeof options.methodNotAllowed === 'function') {
                notAllowedThrowable = options.methodNotAllowed(); // set whatever the user returns from their function
              } else {
                notAllowedThrowable = new HttpError.MethodNotAllowed();
              }
              throw notAllowedThrowable;
            } else {
              ctx.status = 405;
              ctx.set('Allow', allowedArr.join(', '));
            }
          }
        }
      }
    });
  };
github fastify / fastify-sensible / lib / httpErrors.js View on Github external
methodNotAllowed: function methodNotAllowed (message) {
    return new createError.MethodNotAllowed(message)
  },