返回HTTP错误并向错误添加信息

时间:2020-07-23 09:57:56

标签: nestjs

如何为http错误添加信息?

想象一下以下情况:

  • 服务A向服务B发送请求
  • 服务B向服务C发送请求
  • 服务C不可用
  • 服务B的请求失败,并将错误返回给服务A,但应添加一些其他信息

服务B看起来像这样:

    @Get()
    async request() {
      try {
        const res = await this.httpsService.get("http://localhost:3000/account-worth").toPromise()
        return res;
      } catch (error) {
        error.info = "Some Info" // Add some information to the error
        return error;
      }
    }

在服务A中,我需要检索此信息。

0 个答案:

没有答案