【问题标题】:Ignore HTTP 404 Error in opossum circuitbreaker?忽略负鼠断路器中的 HTTP 404 错误?
【发布时间】:2021-01-30 17:57:23
【问题描述】:

我正在构建一个 express api,并使用负鼠在其中实现了一个断路器。

有没有办法让断路器忽略应用程序生成的自定义 HTTP 异常? 我尝试添加 errorFilter 选项,但遇到了同样的问题。它仍在将其视为电路故障。

   const options: CircuitOptions = {
        timeout: 3000, // If function takes longer than 3 seconds, trigger a failure
        errorThresholdPercentage: 50, // When 50% of the requests fail, trip the circuit
        resetTimeout: 30000, // After 30 seconds try again
        errorFilter: err => {
            // Filtering out Http404Error here.
            return err.status === 404 // Not Working
        }
    }

【问题讨论】:

    标签: javascript node.js typescript express circuit-breaker


    【解决方案1】:

    在opossum-playground repo下有一个使用errorFilter属性的opossum示例

    https://github.com/nodeshift-starters/opossum-playground/tree/master/error-filter

    现在,在您的情况下,err.status 可能没有返回状态代码,而是未定义(我在这里猜测,因为我没有完整的代码)并且从 errorFilter 返回的值不是真实的。

    所以负鼠一直认为它是失败的。

    【讨论】:

      猜你喜欢
      • 2012-07-13
      • 1970-01-01
      • 2015-12-29
      • 1970-01-01
      • 2015-11-02
      • 1970-01-01
      • 2018-09-06
      • 1970-01-01
      • 2012-03-30
      相关资源
      最近更新 更多