當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。