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


TypeScript Boom.isBoom函数代码示例

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


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

示例1: it

    it('should create a Boom.badRequest error object', () => {
      const error = Schema.createValidationError();
      const errorWithData = Schema.createValidationError({
        schema: exampleSchema,
        data: {
          id: 1,
          name: 'John Smith',
          comment: 'A long comment about this generic person',
        },
      });

      // Assertions
      expect(Boom.isBoom(error)).toBe(true);
      expect(error.message).toBe('No data provided');
      expect(error.data).toEqual({
        errors: [],
        schema: undefined,
      });
      expect(Boom.isBoom(errorWithData)).toBe(true);
      expect(errorWithData.message).toBe('Invalid data provided');
      expect(errorWithData.data).toEqual({
        errors: [],
        schema: exampleSchema,
        validatedData: {
          comment: 'A long comment about this generic person',
          id: 1,
          name: 'John Smith',
        },
      });
    });
开发者ID:komapijs,项目名称:komapi,代码行数:30,代码来源:Schema.ts

示例2: it

  it('throws if either value is not an integer', () => {
    let error;
    try {
      decodeVersion('WzEsMy41XQ==');
    } catch (err) {
      error = err;
    }

    expect(error.message).toMatchInlineSnapshot(`"Invalid version [WzEsMy41XQ==]"`);
    expect(Boom.isBoom(error)).toBe(true);
    expect(error.output).toMatchInlineSnapshot(`
Object {
  "headers": Object {},
  "payload": Object {
    "error": "Bad Request",
    "message": "Invalid version [WzEsMy41XQ==]",
    "statusCode": 400,
  },
  "statusCode": 400,
}
`);
  });
开发者ID:elastic,项目名称:kibana,代码行数:22,代码来源:decode_version.test.ts

示例3: 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

示例4: getErrorStatusCode

export function getErrorStatusCode(error: any): number {
  return Boom.isBoom(error) ? error.output.statusCode : error.statusCode || error.status;
}
开发者ID:elastic,项目名称:kibana,代码行数:3,代码来源:errors.ts


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