How to use the boom.conflict 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 novomatic-tech / keycloak-kibana / kibana / plugins / keycloak-kibana / server / services / PermissionService.js View on Github external
async _revokePermission(documentId, permission, script, userIds = null) {
    const updateParams = this._getPermissionUpdateScriptParams({ documentId, permission, userIds, script });
    try {
      await this._cluster.callWithInternalUser('update', updateParams);
    } catch (e) {
      console.warn(e);
      const reason = _.get(e, 'body.error.caused_by.caused_by.reason');
      if (reason === 'conflict') {
        throw Boom.conflict(`Cannot revoke permission for a single user when all users can ${permission} the resource.`);
      } else if (reason === 'forbidden') {
        throw Boom.forbidden('The user is not authorized to remove the permissions for the resource.');
      } else if (reason === 'own_removal') {
        throw Boom.badRequest('Permissions for the creator of the resource can\'t be revoked.');
      }
      throw Boom.internal('Failed to alter permissions for the resource.', e.body.error);
    }
  }
github sinfo / cannon-api / server / resources / link.js View on Github external
Link.create(link, (err, _link) => {
    if (err) {
      if (err.code === 11000) {
        return cb(Boom.conflict(`Link "${link.id}" is a duplicate`))
      }

      log.error({err: err, link: link}, 'error creating link')
      return cb(Boom.internal())
    }

    cb(null, _link.toObject({ getters: true }))
  })
}
github iyobo / jollofjs / packages / jollof-app / app / controllers / authController.js View on Github external
exports.doSignup = async (ctx) => {

    const User = jollof.models.User;
    const email = ctx.request.fields.email;

    //first check if user exists
    if ((await User.exists(email)) === true) {
        return ctx.throw(new boom.conflict(`User with email ${email} already exists`));
    }


    await User.persist(ctx.request.fields);

    //Use email of new user as username
    ctx.request.fields.username = ctx.request.fields.email;

    await exports.doLogin(ctx);
}
github JKHeadley / appy-backend / backend / server / api / user.js View on Github external
.then(function (user) {

            if (user) {
              return reply(Boom.conflict('Email already in use.'));
            }

            return reply(true);
          })
          .catch(function (error) {
github hapi-learning / hapi-learning / app / utils / error.js View on Github external
server.decorate('reply', 'conflict', function (message) {

        message = message || 'A conflict has occured, resource may already exists or be deleted';
        return this.response(Boom.conflict(message));
    });
github sinfo / eventdeck / server / resources / company.js View on Github external
Company.create(company, function (err, _company) {
    if (err) {
      if (err.code === 11000) {
        log.warn({err: err, requestedCompany: company.id}, 'company is a duplicate')
        return cb(Boom.conflict(dupKeyParser(err.err) + ' is a duplicate'))
      }

      log.error({err: err, company: company}, 'error creating company')
      return cb(Boom.internal())
    }
    cb(null, _company.toObject({ getters: true }))
  })
}
github jedireza / aqua / server / api / admins.js View on Github external
User.findByUsername(request.payload.username, (err, user) => {

                            if (err) {
                                return reply(err);
                            }

                            if (!user) {
                                return reply(Boom.notFound('User document not found.'));
                            }

                            if (user.roles &&
                                user.roles.admin &&
                                user.roles.admin.id !== request.params.id) {

                                return reply(Boom.conflict('User is already linked to another admin. Unlink first.'));
                            }

                            reply(user);
                        });
                    }
github futurestudio / hapi-rethinkdb-dash / server / core / users.js View on Github external
}).then(function (users) {
      if (_.isEmpty(users)) {
        return when.resolve(user)
      } else {
        return when.reject(Boom.conflict('E-Mail address is already registered.'))
      }
    }).then(function (user) {
      return user.save()
github auth0 / wt-cli / bin / profile.js View on Github external
.then(function (override) {
                    if (!override)
                        throw Boom.conflict('User chose not to override '
                            + 'existing profile.', profile);
                });
        })
github sirensolutions / sentinl / server / lib / handle_es_error.js View on Github external
module.exports = function handleESError(error) {
  if (!(error instanceof Error)) {
    throw new Error('Expected an instance of Error');
  }

  if (error instanceof esErrors.ConnectionFault ||
    error instanceof esErrors.ServiceUnavailable ||
    error instanceof esErrors.NoConnections ||
    error instanceof esErrors.RequestTimeout) {
    return Boom.serverTimeout(error);
  } else if (error instanceof esErrors.Conflict || _.includes(error.message, 'index_template_already_exists')) {
    return Boom.conflict(error);
  } else if (error instanceof esErrors[403]) {
    return Boom.forbidden(error);
  } else if (error instanceof esErrors.NotFound) {
    return Boom.notFound(error);
  } else if (error instanceof esErrors.BadRequest) {
    return Boom.badRequest(error);
  } else if (error.status || error.statusCode) {
    return Boom.boomify(error, { statusCode: error.status || error.statusCode });
  } else {
    return error;
  }
};