How to use the http-errors.NotImplemented 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 koajs / router / lib / router old.js View on Github external
if (!ctx.status || ctx.status === 404) {
        ctx.matched.forEach((route) => {
          route.methods.forEach((method) => {
            allowed[method] = method;
          });
        });

        const allowedArr = Object.keys(allowed);

        if (!~implemented.indexOf(ctx.method)) {
          if (options.throw) {
            let notImplementedThrowable;
            if (typeof options.notImplemented === 'function') {
              notImplementedThrowable = options.notImplemented(); // set whatever the user returns from their function
            } else {
              notImplementedThrowable = new HttpError.NotImplemented();
            }
            throw notImplementedThrowable;
          } else {
            ctx.status = 501;
            ctx.set('Allow', allowedArr.join(', '));
          }
        } else if (allowedArr.length) {
          if (ctx.method === 'OPTIONS') {
            ctx.status = 200;
            ctx.body = '';
            ctx.set('Content-Length', 0);
            ctx.set('Allow', allowedArr.join(', '));
          } else if (!allowed[ctx.method]) {
            if (options.throw) {
              let notAllowedThrowable;
              if (typeof options.methodNotAllowed === 'function') {
github ShieldBattery / ShieldBattery / server / lib / api / matchmakingPreferences.js View on Github external
async function upsertPreferences(ctx, next) {
  const { matchmakingType } = ctx.params
  const { race, alternateRace, mapPoolId, preferredMaps } = ctx.request.body

  if (!isValidMatchmakingType(matchmakingType)) {
    throw new httpErrors.BadRequest('invalid matchmaking type')
  } else if (!isValidRace(race)) {
    throw new httpErrors.BadRequest('invalid race')
  } else if (!(await isValidMapPoolId(mapPoolId))) {
    throw new httpErrors.NotImplemented('map pool support not implemented yet')
  } else if (
    alternateRace !== null &&
    alternateRace !== undefined &&
    !isValidAlternateRace(alternateRace)
  ) {
    throw new httpErrors.BadRequest('invalid alternateRace')
  } else if (preferredMaps !== undefined && preferredMaps !== null) {
    // TODO(2Pac): Change this once matchmaking map pool support is added
    throw new httpErrors.NotImplemented('preferredMaps support not implemented yet')
  }

  ctx.body = await upsertMatchmakingPreferences(
    ctx.session.userId,
    matchmakingType,
    race,
    alternateRace,
github physiii / open-automation / node_modules / koa-router / lib / router.js View on Github external
if (!ctx.status || ctx.status === 404) {
        ctx.matched.forEach(function (route) {
          route.methods.forEach(function (method) {
            allowed[method] = method;
          });
        });

        var allowedArr = Object.keys(allowed);

        if (!~implemented.indexOf(ctx.method)) {
          if (options.throw) {
            var notImplementedThrowable;
            if (typeof options.notImplemented === 'function') {
              notImplementedThrowable = options.notImplemented(); // set whatever the user returns from their function
            } else {
              notImplementedThrowable = new HttpError.NotImplemented();
            }
            throw notImplementedThrowable;
          } 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
github koajs / router / lib / router.js View on Github external
if (!ctx.status || ctx.status === 404) {
        ctx.matched.forEach(function (route) {
          route.methods.forEach(function (method) {
            allowed[method] = method;
          });
        });

        var allowedArr = Object.keys(allowed);

        if (!~implemented.indexOf(ctx.method)) {
          if (options.throw) {
            var notImplementedThrowable;
            if (typeof options.notImplemented === 'function') {
              notImplementedThrowable = options.notImplemented(); // set whatever the user returns from their function
            } else {
              notImplementedThrowable = new HttpError.NotImplemented();
            }
            throw notImplementedThrowable;
          } 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
github ShieldBattery / ShieldBattery / server / lib / api / matchmakingPreferences.js View on Github external
if (!isValidMatchmakingType(matchmakingType)) {
    throw new httpErrors.BadRequest('invalid matchmaking type')
  } else if (!isValidRace(race)) {
    throw new httpErrors.BadRequest('invalid race')
  } else if (!(await isValidMapPoolId(mapPoolId))) {
    throw new httpErrors.NotImplemented('map pool support not implemented yet')
  } else if (
    alternateRace !== null &&
    alternateRace !== undefined &&
    !isValidAlternateRace(alternateRace)
  ) {
    throw new httpErrors.BadRequest('invalid alternateRace')
  } else if (preferredMaps !== undefined && preferredMaps !== null) {
    // TODO(2Pac): Change this once matchmaking map pool support is added
    throw new httpErrors.NotImplemented('preferredMaps support not implemented yet')
  }

  ctx.body = await upsertMatchmakingPreferences(
    ctx.session.userId,
    matchmakingType,
    race,
    alternateRace,
    mapPoolId,
    preferredMaps,
  )
}
github fastify / fastify-sensible / lib / httpErrors.js View on Github external
notImplemented: function notImplemented (message) {
    return new createError.NotImplemented(message)
  },
github strongloop / loopback-next / packages / rest / src / rest-http-error.ts View on Github external
export function invalidParamLocation(location: string): HttpErrors.HttpError {
    const msg = `Parameters with "in: ${location}" are not supported yet.`;
    return new HttpErrors.NotImplemented(msg);
  }
github ShieldBattery / ShieldBattery / server / lib / api / invites.js View on Github external
async function acceptInvite(ctx, next) {
  if (!isValidEmail(ctx.params.email)) {
    throw new httpErrors.BadRequest('Invalid email')
  }
  if (!ctx.request.body.isAccepted) {
    throw new httpErrors.NotImplemented('Not implemented')
  }

  const token = cuid()

  await transact(async client => {
    const invite = await invites.accept(client, ctx.params.email, token)
    await sendMail({
      to: invite.email,
      subject: 'Welcome to ShieldBattery',
      templateName: 'invite',
      templateData: {
        email: invite.email,
        escapedEmail: encodeURIComponent(invite.email),
        token: invite.token,
        feedbackUrl: config.feedbackUrl,
        installerUrl: `${config.canonicalHost}/installer.msi`,