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

TypeScript Boom.wrap函数代码示例

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

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



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

示例1: handleRequestError

export function handleRequestError(friend: User, e: Error, log: any, looped?: boolean, reply?: h.IReply) {
	let code: number = 500; // Default value
	let message: string = ''; // Default value
	if(e instanceof r.RequestError) {
		code = e.error.code;
	} else if(e instanceof r.StatusCodeError) {
		code = e.statusCode;
	}
	
	if(e instanceof r.StatusCodeError && e.statusCode === 400) {
		message = 'This usually means the API was badly implemented either on the current instance or on the friend\'s.';
	} else if(e instanceof r.StatusCodeError && e.statusCode === 401) {
		message = 'This can happen because of a bad implementation of the Vinimay API on either side, or because of an instance domain mismatch between the two instances\' databases.';
	} else if(e instanceof r.StatusCodeError && e.statusCode === 500) {
		message = 'This can happen because of a bug in the remote instance\'s code or a bad implentation of the Vinimay API on its side.'
	} else if(e instanceof r.StatusCodeError) {
		// Some errors are thrown willingly to be sent to the client
		if(reply && !looped) return reply(b.create(e.statusCode));
		else return;
	} else if(!(e instanceof r.RequestError)) {
		log.error(e);
		if(reply && !looped) return reply(b.wrap(e));
		else return;
	}

	// Default behaviour
	if(code) log.warn('Got a ' + code + ' when querying ' + friend)
	else log.error(e);
	if(message.length) log.warn(message);
	if(reply && !looped) reply(b.serverUnavailable());
}
开发者ID:JosephCaillet,项目名称:cozy-vinimay,代码行数:31,代码来源:serverUtils.ts


示例2: async

    handler: async (request, reply) => {
      const timings = {
        esRequestSent: Date.now(),
        esResponseProcessed: 0,
      };

      try {
        const search = <Hit>(params: SearchParams) =>
          callWithRequest<Hit>(request, 'search', params);

        const searchResults = await fetchSearchResultsBetween(
          search,
          request.payload.indices,
          request.payload.fields,
          request.payload.start,
          request.payload.end,
          request.payload.query
        );

        timings.esResponseProcessed = Date.now();

        return reply({
          results: searchResults,
          timings,
        });
      } catch (requestError) {
        return reply(Boom.wrap(requestError));
      }
    },
开发者ID:salihkardan,项目名称:kibana,代码行数:29,代码来源:contained_search_results.ts


示例3: async

        authenticate: async (request, reply) =>
        {
            function unauthorized()
            {
                const response = request.generateResponse().redirect(AuthRoutes.GetLogin);
                

                // Response is ignored if error is passed in as first param
                return reply(null, response);
            }

            let auth: {credentials: AuthCredentials; artifacts: AuthArtifacts};

            try
            {
                auth = await getUserAuth(request);
            }
            catch (e)
            {
                if (e.status === 404)
                {
                    return unauthorized();
                }

                return reply(boom.wrap(e));
            }

            if (!auth)
            {
                return unauthorized();
            }
            
            return reply.continue(auth);
        }
开发者ID:yashodhank,项目名称:deliver-on,代码行数:34,代码来源:auth.ts


示例4: rep

 .catch((err) => {
   if (err.name && err.name === 'SequelizeValidationError') {
     rep(badRequest(err.errors[0].message));
   }
   else {
     rep(wrap(err));
   }
 });
开发者ID:repositive,项目名称:hapi-path-generator,代码行数:8,代码来源:index.ts


示例5: reply

    transporter.sendMail(message, (error, info) =>
    {
        if (error)
        {
            return reply(boom.wrap(error));
        }

        return reply.redirect(Routes.GetResetSent);
    });
开发者ID:nozzlegear,项目名称:deliver-on,代码行数:9,代码来源:auth-routes.ts


示例6: next

            transporter.sendMail(message as any, (error, info) => {
                if (error) {
                    return next(boom.wrap(error));
                };

                res.json({});

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


示例7: isBoomError

    app.use(function (err: Error | BoomError, req: express.Request, res: express.Response, next: Function) {
        const fullError = isBoomError(err) ? err : wrap(err);

        if (fullError.output.statusCode >= 500) {
            inspect(`Error in ${req.url}`, err);
        }

        res.status(fullError.output.statusCode).json(fullError.output.payload);

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


示例8: async

    handler: async (request, reply) => {
      const timings = {
        esRequestSent: Date.now(),
        esResponseProcessed: 0,
      };

      try {
        const search = <Hit>(params: SearchParams) =>
          callWithRequest<Hit, any>(request, 'search', params);

        const latestTime = await fetchLatestTime(
          search,
          request.payload.indices,
          request.payload.fields.time
        );
        const searchResultsAfterTarget = await fetchSearchResults(
          search,
          request.payload.indices,
          request.payload.fields,
          {
            tiebreaker: request.payload.target.tiebreaker - 1,
            time: request.payload.target.time,
          },
          request.payload.after,
          'asc',
          request.payload.query,
          request.payload.target.time + INITIAL_HORIZON_OFFSET,
          latestTime
        );
        const searchResultsBeforeTarget = (await fetchSearchResults(
          search,
          request.payload.indices,
          request.payload.fields,
          request.payload.target,
          request.payload.before,
          'desc',
          request.payload.query,
          request.payload.target.time - INITIAL_HORIZON_OFFSET
        )).reverse();

        timings.esResponseProcessed = Date.now();

        return reply({
          results: {
            after: searchResultsAfterTarget,
            before: searchResultsBeforeTarget,
          },
          timings,
        });
      } catch (requestError) {
        return reply(Boom.wrap(requestError));
      }
    },
开发者ID:salihkardan,项目名称:kibana,代码行数:53,代码来源:adjacent_search_results.ts


示例9: reply

export async function updateAccount(server: Server, request: Request, reply: IReply)
{
    const id = request.params["id"];
    const apiKey = request.auth.credentials.apiKey;
    const accountToUpdate: Account = request.payload;
    let dbAccount: Account;

    // Get the original account
    try
    {
        dbAccount = await Accounts.findByApiKey(apiKey);

        // Only update the account if the ApiKey and Id match.
        if (!dbAccount || dbAccount._id !== id || dbAccount.apiKey !== apiKey)
        {
            return reply(notFound("No account find with that id and API key combination."));
        }
    }
    catch (e)
    {
        console.error("Failed to retrieve account when updating.", e);

        return reply(boom(e));
    }

    // Transfer update props to the dbAccount
    for (let prop in accountToUpdate)
    {
        dbAccount[prop] = accountToUpdate[prop];
    }

    // Never update the account's ID or apiKey
    dbAccount._id = id;
    dbAccount.apiKey = apiKey;

    try
    {
        const update = await Accounts.Database.put(accountToUpdate);

        if (!update.ok)
        {
            console.error("Failed to update account.", update);

            return reply(expectationFailed("Failed to update account."));
        }
        
        dbAccount._rev = update.rev;
    }
    catch (e)
    {
        console.error("Failed to update account.", e);

        return reply(boom(e));
    }

    return reply(dbAccount);
}
开发者ID:nozzlegear,项目名称:stages-api,代码行数:57,代码来源:accounts-routes.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript bootbox.alert函数代码示例发布时间:2022-05-25
下一篇:
TypeScript Boom.unauthorized函数代码示例发布时间: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