当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ResponseToolkit.response方法代码示例

本文整理汇总了TypeScript中hapi.ResponseToolkit.response方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ResponseToolkit.response方法的具体用法?TypeScript ResponseToolkit.response怎么用?TypeScript ResponseToolkit.response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hapi.ResponseToolkit的用法示例。


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

示例1: async

      handler: async (request: Request, h: ResponseToolkit) => {
        try {
          const { method } = request;
          const query =
            method === 'post'
              ? (request.payload as Record<string, any>)
              : (request.query as Record<string, any>);

          const graphQLResponse = await runHttpQuery([request], {
            method: method.toUpperCase(),
            options: options.graphQLOptions,
            query,
          });

          return h.response(graphQLResponse).type('application/json');
        } catch (error) {
          if (error.isGraphQLError === true) {
            return h
              .response(error.message)
              .code(error.statusCode)
              .type('application/json');
          }
          return h.response(error).type('application/json');
        }
      },
开发者ID:liuyepiaoxiang,项目名称:kibana,代码行数:25,代码来源:apollo_framework_adapter.ts

示例2: async

      handler: async (request: Request, h: ResponseToolkit) => {
        try {
          const query =
            request.method === 'post'
              ? (request.payload as Record<string, any>) // eslint-disable-line @typescript-eslint/no-explicit-any
              : (request.query as Record<string, any>); // eslint-disable-line @typescript-eslint/no-explicit-any

          const gqlResponse = await runHttpQuery([request], {
            method: request.method.toUpperCase(),
            options: options.graphqlOptions,
            query,
          });

          return h.response(gqlResponse).type('application/json');
        } catch (error) {
          if ('HttpQueryError' !== error.name) {
            const queryError = Boom.boomify(error);

            queryError.output.payload.message = error.message;

            return queryError;
          }

          if (error.isGraphQLError === true) {
            return h
              .response(error.message)
              .code(error.statusCode)
              .type('application/json');
          }

          const genericError = new Boom(error.message, { statusCode: error.statusCode });

          if (error.headers) {
            Object.keys(error.headers).forEach(header => {
              genericError.output.headers[header] = error.headers[header];
            });
          }

          // Boom hides the error when status code is 500

          genericError.output.payload.message = error.message;

          throw genericError;
        }
      },
开发者ID:,项目名称:,代码行数:45,代码来源:

示例3: handler

  async function handler(exportTypeId: any, jobParams: any, request: Request, h: ResponseToolkit) {
    // @ts-ignore
    const user = request.pre.user;
    const headers = request.headers;

    const job = await enqueueJob(exportTypeId, jobParams, user, headers, request);

    // return the queue's job information
    const jobJson = job.toJSON();

    return h
      .response({
        path: `${DOWNLOAD_BASE_URL}/${jobJson.id}`,
        job: jobJson,
      })
      .type('application/json');
  }
开发者ID:elastic,项目名称:kibana,代码行数:17,代码来源:index.ts

示例4:

 handler: (request: Request, h: ResponseToolkit) => {
     return h.response('success')
     .type('text/plain')
     .header('X-Custom', 'some-value');
 }
开发者ID:RomkeVdMeulen,项目名称:DefinitelyTyped,代码行数:5,代码来源:response.ts

示例5:

const success = (h: ResponseToolkit) => {
    return h.response({ status: 'ok' });
};
开发者ID:RomkeVdMeulen,项目名称:DefinitelyTyped,代码行数:3,代码来源:server-decorations.ts

示例6:

 handler: (request: Request, h: ResponseToolkit) => {
     return h.response("Hello World");
 }
开发者ID:dvine-multimedia,项目名称:DefinitelyTyped,代码行数:3,代码来源:server-table.ts

示例7:

const handler = (request: Request, h: ResponseToolkit) => {
    return h.response('The page was not found').code(404);
};
开发者ID:RomkeVdMeulen,项目名称:DefinitelyTyped,代码行数:3,代码来源:catch-all.ts

示例8:

 handler: (request: Request, h: ResponseToolkit) => {
     return h.response('Hello').state('data', { firstVisit: false });
 }
开发者ID:RomkeVdMeulen,项目名称:DefinitelyTyped,代码行数:3,代码来源:server-state.ts


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