• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript Boom.notAcceptable函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中Boom.notAcceptable函数的典型用法代码示例。如果您正苦于以下问题:TypeScript notAcceptable函数的具体用法?TypeScript notAcceptable怎么用?TypeScript notAcceptable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了notAcceptable函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: createUser

export async function createUser(server: Server, request: Request, reply: IReply)
{
    const payload = request.payload as {name: string, username: string, password: string, accountId: string};
    const account = await Accounts.Database.get<Account>(payload.accountId.toLowerCase());

    if (!account)
    {
        return reply(notAcceptable(`No account with id of ${payload.accountId} exists.`));
    }

    // Ensure adding another user won't go over the account's plan limit.
    const userCount = await Users.countByAccountId(payload.accountId.toLowerCase());
    const plan = findPlan(account.planId);
    
    if (userCount >= plan.totalUsers)
    {
        return reply(notAcceptable("Account's plan has reached its maximum number of users."));
    }

    let user: User = {
        _id: payload.username,
        _rev: undefined,
        accountId: payload.accountId.toLowerCase(),
        hashedPassword: hashSync(payload.password, 10),
        name: payload.name,
    }

    try
    {
        const update = await Users.Database.put(user);

        if (!update.ok)
        {
            return reply(expectationFailed("Failed to create user.", update));
        }

        user._rev = update.rev;
    }
    catch (e)
    {
        console.error("Error thrown when creating user", e);

        throw e;
    }

    // Do not reflect the user's hashedPassword.
    user.hashedPassword = undefined;

    return reply(user).code(201);
}
开发者ID:nozzlegear,项目名称:stages-api,代码行数:50,代码来源:users-routes.ts


示例2: getSearchDsl

export function getSearchDsl(
  mappings: IndexMapping,
  schema: SavedObjectsSchema,
  options: GetSearchDslOptions
) {
  const {
    type,
    search,
    defaultSearchOperator,
    searchFields,
    sortField,
    sortOrder,
    namespace,
    hasReference,
  } = options;

  if (!type) {
    throw Boom.notAcceptable('type must be specified');
  }

  if (sortOrder && !sortField) {
    throw Boom.notAcceptable('sortOrder requires a sortField');
  }

  return {
    ...getQueryParams(
      mappings,
      schema,
      namespace,
      type,
      search,
      searchFields,
      defaultSearchOperator,
      hasReference
    ),
    ...getSortingParams(mappings, type, sortField, sortOrder),
  };
}
开发者ID:elastic,项目名称:kibana,代码行数:38,代码来源:search_dsl.ts


示例3: function

        handler: async function (req, res, next) {
            const query: Requests.GetOauthUrl = req.validatedQuery;
            const isValidUrl = await Auth.isValidShopifyDomain(req.validatedQuery.shop_domain);

            if (!isValidUrl) {
                return next(boom.notAcceptable(`${query.shop_domain} is not a valid Shopify shop domain.`));
            }

            const authUrl = await Auth.buildAuthorizationUrl(Constants.DEFAULT_SCOPES, req.validatedQuery.shop_domain, Constants.SHOPIFY_API_KEY, query.redirect_url);

            res.json({ url: authUrl });

            return next();
        }
开发者ID:nozzlegear,项目名称:Gearworks,代码行数:14,代码来源:shopify.ts


示例4: errorHandlerMiddleware

  return async function errorHandlerMiddleware(ctx, next) {
    try {
      await next();
      if (ctx.status === 404) throw Boom.notFound();
    } catch (applicationError) {
      const err: ApplicationError = applicationError;
      let error: Boom<any>;

      // Normalize error object
      try {
        if (!(applicationError instanceof Error)) throw new Error('Cannot handle non-errors as errors');
        error = Boom.isBoom(err)
          ? err
          : Boom.boomify(err, {
              statusCode: err.status || err.statusCode || undefined,
              decorate: err.data,
            });
      } catch (subError) {
        error = Boom.boomify(subError);
      }

      // Set defaults
      let status = Boom.notAcceptable().output.statusCode;
      let headers = {};
      let body: string | object = Boom.notAcceptable().output.payload.message;

      // Check for dev and include dev stuff
      if (ctx.app.env !== 'production') {
        error.output.payload.additionalDevelopmentData = {
          data: error.data || undefined,
          stack: error.isServer && error.stack ? error.stack : undefined,
        };
      }

      // Convert boom response to proper format
      const payload = {
        error: {
          code: error.output.payload.code || '',
          status: error.output.payload.statusCode,
          error: error.output.payload.error,
          message: error.output.payload.message,
          errors: error.output.payload.errors,
          additionalDevelopmentData: error.output.payload.additionalDevelopmentData,
        },
      };

      // Respond with the proper format
      const format = ctx.accepts(['json', 'text']);
      if (format === 'json') {
        status = error.output.statusCode;
        headers = error.output.headers;
        body = payload;
      } else if (format === 'text') {
        status = error.output.statusCode;
        headers = error.output.headers;
        body = payload.error.message;
      }

      // Respond with the error
      ctx.set(headers);
      ctx.status = status;
      ctx.body = body;
    }
  };
开发者ID:komapijs,项目名称:komapi,代码行数:64,代码来源:errorHandler.ts



注:本文中的Boom.notAcceptable函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript Boom.notFound函数代码示例发布时间:2022-05-25
下一篇:
TypeScript Boom.isBoom函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap