Ignore HTTP 404 Error in opossum circuitbreaker

1.3k views Asked by At

I am building an express api and have implemented a circuit breaker in it using opossum.

Is there a way for the circuit breaker to ignore the custom HTTP exceptions generated from application?

I have tried adding the errorFilter option but getting the same issue. It is still considering it as a circuit failure.

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
    }
}
2

There are 2 answers

0
J.F. On

Just resolved the same issue.

In my case I was doing the request using axios so the response status is into err.response.status. And in the same way that point alexalikiotis, using err.status === 404 it was evaluated as undefined === 404.

So this code works fine for me doing calls over the network using axios:

errorFilter: err => {
    return err.response.status === 404
}
0
alexalikiotis On

There is an opossum example using the errorFilter property under the opossum-playground repo

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

Now, in your case probably the err.status is not returning the status code but an undefined (I'm guessing here since I don't have the full code) and the value returned from the errorFilter is not truthy.

So opossum keeps considering it a failure.